BuddyDev

Search

[Resolved] How to custom sort group posts (Blog Categories for Groups plugin)?

  • Participant
    Level: Initiated
    Posts: 5
    Hob Nob on #33233

    I’m using the pre_get_posts filter (shown below) to sort my homepage post loop by a custom metavalue.

    function custom_loop_for_loggedin_users( $query ) {
        if ( is_user_logged_in() && $query->is_home() && $query->is_main_query() && ! is_admin() ) {
    	    $user_cat_ids = get_category_ids_of_bp_groups( bp_loggedin_user_id() );
    	    $tax_query = array(
    	        array(
    	            'taxonomy' => 'category',
    	            'field'    => 'term_id',
    	            'terms'    => $user_cat_ids,
    	        ),
    	    );
    	    $query->set( 'tax_query', $tax_query );
    	    $query->set( 'meta_key', 'hot_rank_score_cached' );	    
    	    $query->set( 'orderby', array('hot_rank_score_cached' => 'DESC', 'date' => 'DESC'));
        }
    }
    add_action('pre_get_posts','custom_loop_for_loggedin_users');

    But I’m also using the Blog Categories for Groups plugin, and would like to apply a similar custom sort to the group blog posts.

    I’ve been digging through your plugin to see how you query those posts, but I can’t figure it out.

    Am I able to apply a custom sort to the group blog posts? Can you point me in the right direction?

    Was hoping to use something like pre_get_posts or WP_Query if possible.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #33242

    Hello Hob,

    Thank you for posting. Please take a look on the following URL:

    https://github.com/buddydev/blog-categories-for-groups/blob/master/core/bcg-template.php#L27

    you can modify using ‘bcg_get_query’ this filter.

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 5
    Hob Nob on #33246

    Amazing, thanks that did it.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #33247

    Hello Hob

    Thank you for the acknowledgement.

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: resolved