Php 在query_posts()中组合tax_查询和meta_查询
我尝试使用预定义的元值获取自定义帖子。查询不返回任何内容Php 在query_posts()中组合tax_查询和meta_查询,php,wordpress,Php,Wordpress,我尝试使用预定义的元值获取自定义帖子。查询不返回任何内容 $args = array ( 'post_type' => 'item', 'nopaging' => true, 'tax_query' => array ( array ( 'taxonomy' => $taxonomy, 'field' => 't
$args = array
(
'post_type' => 'item',
'nopaging' => true,
'tax_query' => array
( array
(
'taxonomy' => $taxonomy,
'field' => 'term_taxonomy_id',
'terms' => $term_id
)
),
'meta_query' => array(
array(
'key' => 'from_import',
'value' => '1',
)
)
);
$posts = query_posts( $args );
当我删除meta_查询或tax_查询时,它可以正常工作。如何组合它?我相信这会修复您的代码。我还没有真正运行它,但尝试一下。每一个都有一个额外的“array()”
$args = array
(
'post_type' => 'item',
'nopaging' => true,
'tax_query' => array
(
'taxonomy' => $taxonomy,
'field' => 'term_taxonomy_id',
'terms' => $term_id
),
'meta_query' => array(
'key' => 'from_import',
'value' => '1'
)
);
$posts = query_posts( $args );
我只是浏览了一下,这里有一个我在我的场景中使用的工作片段,根据需要调整以满足您的需要
// Bring post from the global context (if not present already).
global $post;
// Define the post_type's to query for.
$post_types = array( 'event', 'post', 'book' );
// Do the weird query.
// Play with, or add arguments as needed https://codex.wordpress.org/Class_Reference/WP_Query
$results = WP_Query(
array(
'post_type' => $post_types,
'tax_query' => array(
array(
'taxonomy' => 'category',
'terms' => wp_get_post_categories( $post->ID )
)
),
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'presenters_people',
'value' => $post->ID,
'compare' => 'LIKE'
),
array(
'key' => 'author',
'value' => $post->ID,
'compare' => 'LIKE'
)
)
)
);
谢谢,但是如果没有第二个箭头
tax\u query
query无法筛选结果。