Support

Account

Home Forums Front-end Issues Not able to sort on custom field

Helping

Not able to sort on custom field

  • Hi all,

    I’m running into problem with sorting on custom fields.

    $args = array(
       'post_type'  => 'page',
       'meta_key'   => '_wp_page_template',
       'meta_value' => 'custom_pages/slot_review.php',
       'posts_per_page'=> 10,
       'paged' => $paged, 
    )

    I have a page where i want to output cards with custom fields from the slot_review.php template. With the query from above i’m able to output the information. What i want to achieve is that i can sort all these results on a specific custom field within that template.

    If i run the following query it filters the cards correctly based on their rating. But i’m not able to sort on that rating to show up the card with the highest rating as first.

    $args = array(
       'post_type'  => 'page',
       'meta_key'   => '_wp_page_template',
       'meta_value' => 'custom_pages/slot_review.php',
       'posts_per_page'=> 10,
       'paged' => $paged, 	
       'meta_query'  => array(
          array(
             'key'     => 'rating',
             'value'   => 87,
             'compare' => '>',
    		        )
    		    )
    		);

    I hope someone can help me out with this 🙂

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.