WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] WP_Query sort by custom filed (3 posts)

  1. Archie22is
    Member
    Posted 1 year ago #

    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

  2. etoed
    Member
    Posted 1 year ago #

    Hi, I have a similar problem, please tell me how to do wordpress.org/support/topic/drop-site-for-sorting-custom-fields

  3. Archie22is
    Member
    Posted 1 year ago #

    ** 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 :-)

Topic Closed

This topic has been closed to new replies.

About this Topic