• Resolved garytamen

    (@garytamen)


    Hello,

    This plugin is great. Thank you for your great work!

    I have added an option with an Advanced Custom Field to the $orderby array and it seems to work perfectly:

    $orderby = strtolower( (string) $orderby );
    	if ( !in_array( $orderby, array( 'post_date', 'post_modified', get_field('show_event_start_date') ) ) ) {
    		$orderby = 'post_date';
    	}

    I feel silly that I can’t figure this out, but how would I implement this through my child theme functions instead of editing the plugin functions?

    Thank you in advance for the help.

    https://wordpress.org/plugins/related-posts-by-taxonomy/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author keesiemeijer

    (@keesiemeijer)

    At this moment this is not possible, but I’m working on an update where you can filter the query like the posts_* filters in WP_Query.

    For orderby this would be similar to the posts_orderby filter
    http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_orderby

    This update is a few weeks away.

    Thread Starter garytamen

    (@garytamen)

    Great, thank you!

    Plugin Author keesiemeijer

    (@keesiemeijer)

    Hi @garytamen

    It took a bit longer but I’ve added the filters in version 0.3.1

    Here is an Example on how you can use it to use the order by an Advanced Custom Field.

    add_filter( 'related_posts_by_taxonomy_posts_orderby', 'related_posts_get_field_orderby', 10, 4 );
    
    function related_posts_get_field_orderby( $order_by_sql, $post_id, $taxonomies, $args ) {
    	global $wpdb;
    
    	if ( !function_exists( 'get_field' ) ) {
    		return $order_by_sql;
    	}
    
    	$orderby = get_field( 'show_event_start_date' );
    
    	if ( !empty( $orderby ) ) {
    		$order_by_sql = "$wpdb->posts.$orderby DESC";
    	}
    
    	return $order_by_sql;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Edit the orderby arg with chid theme functions.php’ is closed to new replies.