Home Forums ACF PRO Return Featured articles first


Return Featured articles first

  • Hey,

    First of all, thank you for greeting me on this forum, i am a free ACF user for some time and have just invested in the Developer package.

    I’m using a wp_query to bring up some posts, on my homepage, working great.
    I created an ACF field “featured” with a true/false type, and i would like the wp_query to still bring up all the posts, but put the ones with featured = 1 first.

    I tried several things including :

    $args = array(
    			    'post_type' => 'post',
    			    'posts_per_page' => 3,
    			    'meta_key'		=> 'featured',
    			    'orderby' => 'meta_value',
    				'order' => 'ASC',

    but right now, the args return only the posts where “featured” has been set at least once.
    How could i achieve that?


  • Try changing to 'order' => 'DESC', When true the value is 1 and 0 for false, never set should be NULL. I’m not sure that this will fix your issue dealing with posts that have never had the field set one way or the other.

  • Hi.

    I had a similar problem where I had a custom post type for FAQ’s and I wanted to put the top five questions at the top then followed by the rest.
    I was tearing my hair out before I saw John’s answer above. At least in my case I had to update all the posts after I had created the custom field I wanted to sort against.

    It could be even more elaborate I guess but this does the trick for me.

    $args = array(
    	'post_type' => 'faq',
    	'posts_per_page' => -1,
    	'meta_key' => 'top_five',
    	'orderby' => 'meta_value',
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Return Featured articles first’ is closed to new replies.