I'm using Advanced Custom Field Plugin and I'm trying to filter some Custom Post by a Taxonomy Field, modifying the WP_Query:
$wp_query = new WP_Query(
array(
'post_type' => 'recursos', // My custom post
'posts_per_page' => 12,
'meta_key' => 'recursos_tipo', // My Taxonomy custom field name
'meta_value' => 'documentos' // My taxonomy slug; the value for filter
)
)
If I try filter by a Text Field everything is fine, the WP_Query is modified. But when the field is a Taxonomy field I don't know what parameter should I pass, because is an object. I've tried the taxonomy name and the taxonomy ID but doesn't work.
Is possible filter by a Taxonomy Field? What parameter for 'meta_value'
should I pass? Thanks!
UPDATE - Structure:
Custom Post: 'recursos'.
Custom Taxonomy Slug: 'recursos-tipos' (Group Taxonomy Slug).
Custom Taxonomy: 'documentos' (Taxonomy Slug).
Custom Taxonomy ID: 16.
ACF Taxonomy Field: 'recursos_tipo'.
UPDATE - 'tax_query'
I've tried with this too, and doesn't work. Show me all the posts:
$wp_query = new WP_Query(
array(
'post_type' => 'recursos',
'posts_per_page' => 12,
'paged' => $paged,
'tax_query' => array(
'taxonomy' => 'recursos-tipos',
'field' => 'slug',
'terms' => 'documentos'
)
)
);
IMPORTANT: I think this is not working because I "assign" the Taxonomies via ACF Taxonomy Field, and it doesn't affect the Tax. My Taxonomies has 0 posts. The tax_query
works fine if the Tax has posts. There is a way to affect the post count of Custom Taxonomy via ACF Taxonomy Field?