• Resolved agentkiller007

    (@agentkiller007)


    Problem is –
    I am using

    $args = array('taxonomy' => 'business_category',);
                      $cats = get_categories($args); 

    to display list of category and when user clicks on one of them,
    resulting page is all businesses that have queried business_category.

    I just want to order these results by there ratings.

    So i tried –

    $query = new WP_Query([
        'meta_query' => [
            ['key' => '_glsr_ranking', 'compare' => '>', 'value' => 0],
        ],
        'order' => 'DESC',
        'orderby' => 'meta_value_num',
        'post_status' => 'publish',
        'post_type' => 'business', // change this as needed
        'posts_per_page' => 10, // change this as needed
    ]);

    , but by this I am loosing my default query i.e, on which the businesses were sorted on the basis of there business_category.
    ////////////////////////////////////////
    Just a guess – Can’t we make use of default URL based query in functions.php file

    function tulip_adjust_queries($query){
    	if (!is_admin() AND is_post_type_archive('business')) {
    		$taxquery = array(
    		        array(
    		              //some code//
    		        )		        
    		    );
    		$query->set('tax_query' ,$taxquery);		
    	}
    }

    PLS Help……..!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    The Help page explains how to order pages with assigned reviews by rank:

    In your case, you will need to use the parse_query WordPress hook to modify the existing query. Using your tulip_adjust_queries example, you could do something like this:

    function tulip_adjust_queries ($query) {
        if (!is_admin() && is_post_type_archive('business')) {
            $query->set('meta_query', [
                'relation' => 'OR',
                ['key' => '_glsr_ranking', 'compare' => 'NOT EXISTS'], // this comes first!
                ['key' => '_glsr_ranking', 'compare' => 'EXISTS'],
            ]);
            $query->set('orderby', 'meta_value_num date');
        }
    }
    add_action('parse_query', 'tulip_adjust_queries');
    
    Thread Starter agentkiller007

    (@agentkiller007)

    It worked… Very Quick and Exact support.
    Thanks……

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Order custom post according to assigned reviews on archive page’ is closed to new replies.