Home › Forums › Backend Issues (wp-admin) › WP_Query using ACF Taxonomy Category › Reply To: WP_Query using ACF Taxonomy Category
I really do not see anything seriously wrong, the only thing I can think of is that you either have the wrong taxonomy name or that the values your trying to use in the query are not integers
// this field can return either a single category or multiple
// ensure that you are only getting the ID values of the terms and not term objects
$categories = get_field('project_slider_category', false, false);
if ($categories) {
if (!is_array($categories)) {
$categories = array($categories);
}
// make sure all values are integers
$categories = array_map('intval', $categories);
}
$args = array(
'post_type' => 'project',
'post_status' => 'publish',
'posts_per_page' => 8,
'orderby' => 'title',
'order' => 'ASC',
'tax_query' => array(
array(
// make sure the category name is "categories"
'taxonomy' => 'categories',
'terms' => $categories
),
),
);
$loop = new WP_Query( $args );
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.