我正在尝试提取具有特定自定义分类的自定义帖子类型
这就是我所尝试的:
$args = array(
\'posts_per_page\' => -1,
\'post_type\' => \'products\',
\'post_status\' => \'publish\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'subjects\',
\'field\' => \'name\',
\'terms\' => $shortcode_atts[\'subject\'],
),
array(
\'taxonomy\' => \'plans\',
\'field\' => \'name\',
\'terms\' => $shortcode_atts[\'plan\'],
),
),
);
$shortcode\\u atts如下所示:
string(80) "Array
(
[subject] => אינטרנט
[plan] => מסלול 10 גיגה
)
"
也就是说,这是希伯来语,主题=互联网,计划=10giga
我还尝试使用operator,不确定在哪个位置添加它,所以我在所有位置都尝试了,但都不起作用。有人能告诉我怎么拉这些柱子吗?
此查询返回所有cpt,不包含我想要的筛选。
编辑:shortcode\\u atts是:
function show_product( $atts, $content = null, $tag ) {
$shortcode_atts = shortcode_atts( array(
\'subject\' => \'\',
\'plan\' => \'\'
), $atts );
}
add_shortcode( \'show_product\', \'show_product\' );
谢谢!
最合适的回答,由SO网友:Max Yudin 整理而成
您可以同时使用多个分类法,因此请使用\'relation\' => \'AND\'
:
<?php
$args = array(
\'posts_per_page\' => -1,
\'post_type\' => \'products\',
\'post_status\' => \'publish\',
\'tax_query\' => array(
\'relation\' => \'AND\', // this is what was missing
array(
\'taxonomy\' => \'subjects\',
\'field\' => \'name\',
\'terms\' => $shortcode_atts[\'subject\'],
),
array(
\'taxonomy\' => \'plans\',
\'field\' => \'name\',
\'terms\' => $shortcode_atts[\'plan\'],
),
),
);