Home › Forums › General Issues › Numberposts & Meta Query Not Working › Reply To: Numberposts & Meta Query Not Working
There is one thing I just noticed as far as the meta_query goes.
First of all, if you’re field is not returning an ID of the “ct_industry” assuming that this is some type of relationship field, then you need to get the unformatted value.
Secondly, since you are searching for numbers in a field that contains arrays then your LIKE needs to be altered.
All of the following are guesses assuming that “ct_industry” is either a taxonomy or a relationship field.
$relatedCat = get_field('service_related_industry', false, false);
$args = array (
'posts_per_page' => 3,
'post_type' => 'case_study',
'meta_query' => array(
array(
'key' => 'cs_industry',
'value' => '"'.$relatedCat.'"',
'compare' => 'LIKE',
)
),
'orderby' => 'DESC',
);
if (!$relatedCat) {
$relatedCat = get_field('service_related_category');
unset ($args);
$args = array (
'posts_per_page' => 3,
'cat' => $relatedCat,
'orderby' => 'DESC',
);
}
as far as why it’s returning the wrong number of posts, yes, a pre_get_post filter added somewhere else can alter the settings of any query done anywhere and any time https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
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.