I have a custom post type which lists a set of colours and the types of products they are available on using an ACF repeater.
The intention is to list CPTs with the appropriate available colours on another page. The availability of a colour is set using a custom taxonomy ('availability')
To achieve this I am running a WP_Query() which filters the post type, anda meta_query. This all works fine if I am querying a text sub_field, but I want to run the query on a custom taxonomy.
Based on the examples found here my code is like so:
Functions:
function my_posts_where( $where ) {
$where = str_replace("meta_key = 'colour_swatch_", "meta_key LIKE 'colour_swatch_", $where);
return $where;
}
add_filter('posts_where', 'my_posts_where');
On my page:
<?php
$args = array(
'post_type' => 'colourswatch',
'meta_query' => array(
array(
'key' => 'colour_swatch_%_availability',
'value' => 'windows',
'compare' => 'LIKE'
)
)
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<p><?php the_title(); ?></p>
<?php
endwhile;
wp_reset_postdata();
?>
This returns back nothing unfortunately, but if I switch 'availability' (the sub_field name for the taxonomy) to 'colour_name' another sub_field I have which is a text field and change the value to 'white' it returns a list of all the colourswatch CPTs featuring white, so I know the basics are working and I assume I have misunderstood how I need to query the taxonomy. Where is this going wrong?