[英]Filter Custom Posts by Taxonomy Custom Field
我正在使用高级自定义字段插件,并尝试通过分类字段过滤一些自定义帖子,修改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
)
)
如果我尝试通过“ 文本字段”进行筛选,一切都很好,那么将修改WP_Query。 但是,当该字段是“分类”字段时,我不知道应该传递什么参数,因为它是一个对象。 我已经尝试过使用分类法名称和分类法ID,但是无法正常工作。
是否可以通过分类字段进行过滤? 我应该为'meta_value'
传递什么参数? 谢谢!
更新-结构:
自定义帖子:“ recursos”。
自定义分类标准子弹:“ recursos-tipos”(组分类标准子弹)。
自定义分类法:“ documentos”(分类标枪)。
自定义分类ID:16。
ACF分类标准字段:“ recursos_tipo”。
更新-'tax_query'
我也尝试过此方法,但不起作用。 显示所有帖子:
$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'
)
)
);
重要提示:我认为这不起作用,因为我通过ACF分类标准字段“分配”了分类标准,并且它不会影响税收。 我的分类法有0个帖子。 如果Tax有职位, tax_query
可以正常工作。 有没有一种方法可以通过ACF分类标准字段影响自定义分类标准的职位数?
您是否尝试过WordPress自定义查询args ,只需将“ Custom_tax”替换为您的Value:如下所示: WordPress WP_Query
<?php
$jabelquery = new WP_Query( array(
'post_type' => 'recursos', // post,page, revision, custom_post_type
'tax_query' => array( //(array) - use taxonomy parameters (available with Version 3.1).
'relation' => 'AND', //(string) - Possible values are 'AND' or 'OR' and is the equivalent of ruuning a JOIN for each taxonomy
array(
'taxonomy' => 'recursos-tipos', //(string) - Taxonomy.
'field' => 'slug', //(string) - Select taxonomy term by ('id' or 'slug')
'terms' => array( 'recursos_tipo' ) //(string) - Operator to test. Possible values are 'IN', 'NOT IN', 'AND'.
)
) )
);
// The Loop
if ( $jabelquery->have_posts() ) :
while ( $jabelquery->have_posts() ) : $jabelquery->the_post(); ?>
<?php the_title(); ?>
<?php endwhile; endif; ?>
那么您可以使用ACF字段替换custom_tax,如下所示:
$jab_tax = get_field('taxonomy_custom_select');
'taxonomy' => $jab_tax,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.