I have a check box custom field “featured portfolio”. There are only 6 posts checked in this specific custom field. I want to show all portfolios but the featured portfolios first.
Here is the query:
$post_query = new \WP_Query(array(
'post_type' => 'portfolio',
'posts_per_page' => -1,
'meta_key' => array('handpicked_projects'),
'orderby' => 'meta_value date',
'order' => 'DESC'
));
I am able to show the featured portfolios. All I want is to show all but featured first.
Hi
Check your code.
new \WP_Query
has a random backslash
'orderby' => 'meta_value date',
you’re ordering by a date field?
You could check the ACF docs on querying by custom fields. The WP Docs show how to order by custom fields
It depends on what type of field the “featured portfolio” field is, you say checkbox, does that mean a true false field?
You need a field that is sortable. A true false field stores a 0 or 1, so it is sortable.
'meta_query' => array(
'featured_clause' => array(
'key' => 'field_name',
'compare' => 'EXISTS'
)
),
// order by featured clause descending, true will be shown first
'orderby' => array('featured_clause' => 'DESC', 'date' => 'DESC')
As I said I have figured out to show the featured projects which are controlled by an ACF field. NOt a big deal to sort them.
All I want is to show other posts which are not featured in this post type.
Like this:
Project 1 (featured)
Project 2 (featured)
Project 3
Project 4
In this case, do I need to run another loop to show non-featured posts? If yes, how would I approach it?
Solved. I was using a single value YES. When I add Yes and NO, it works. But I have to check the YES/NO box every time to return the value. Thanks, John for your awesome plugin.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.