Support » Fixing WordPress » WP_Query sort by custom filed

  • Resolved Archie22is


    Hi guys,

    I want to retrieve the posts into the loop and arrange / filter them by priority. I want the posts marked ‘featured’ to have a higher priority while the rest of the posts can come right below that. I am using the following code.

    $loop = new WP_Query( array(
    	'post_type' => 'company_listing',
    	'cat' => get_query_var('cat'),
    	//'meta_key' => 'featured',
    	//'orderby' => 'yes'

    When ever I comment out the meta_key and the orderby (which is a radio button) it only returns the featured posts and none of the ordinary posts. I also do not wish to return redundadt posts

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi, I have a similar problem, please tell me how to do

    ** shocked by my level of stupidity **

    The above query works 100%. I was testing with only one post marked as “featured” and the rest of the post not marked or registered as not “featured”, thus the one returned post.

    Basically I had to register on all the posts if they were featured or not and then the ‘orderby’ => ‘yes’ took care of the rest. I now get the posts marked “featured” coming first before all the unmarked posts 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WP_Query sort by custom filed’ is closed to new replies.