Although I've read many other answers with the same question on StackOverflow none of them where able to fix the issue I have.
I'm using ACF and have a custom post type called "services". The CPT has a custom taxonomy called "category", this returns the TermID of the taxonomy.
This was working before when I used a standard taxonomy, but since i've switched to the ACF taxonomy it has stopped working.
//This works fine
$serviceName = $wp_query->query_vars['test'];
//CURRENT The loop issue with ACF which doesnt work
$args = array(
'post_type' => 'services',
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $serviceName
)
)
);
//OLD The loop when using standard taxonomy that works
$args = array(
'post_type' => 'services',
'category_name' => $serviceName,
);
//Display
$service_posts = get_posts( $args );
In Functions.php I have created a function which makes the ACF categories filter out the ones I don't want. This is to prevent the user choosing categories which aren't services.
function service_categories( $args, $field, $post_id ) {
$args['orderby'] = 'count';
$args['order'] = 'DESC';
$args['include'] = '6, 7, 8, 9, 10, 15, 16';
return $args;
}
This works on the dashboard, however I wonder if this at all may be interfering at all?
Thank you for your time.
EDIT:
Also noticed when you view all the CPT's the category tab is blank, not sure why this is since as far as I'm aware the ACF should overwrite this anyway.