Home › Forums › General Issues › Get posts by ACF if not exists › Reply To: Get posts by ACF if not exists
you’ve specified a meta key, but not a value
$new_args = [
'post_type' => 'news',
'post_status' => 'publish',
'fields' => 'ids',
'posts_per_page' => '5',
'meta_key' => 'is_featured',
'meta_value' => '1',
'orderby' => 'meta_value_num', // not sure that this does
'order' => 'desc'
];
$news = new WP_Query($new_args);
Either that or you need to use a meta_query parameter. https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters. You need to test for the value and you need to test that the value exists. See the “compare” argument.
'meta_query' => array(
array(
'key' => 'is_featured',
'compare' => 'EXISTS'
),
array(
'key' => 'is_featured',
'value' => '1'
),
),
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.