我想使用自定义字段显示分类法类别中的帖子列表。这是我的代码:
if($current_term->term_id==\'143\') {
$querystr = " SELECT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta, $wpdb->terms wpterms
WHERE wposts.ID = wpostmeta.post_id
AND wpostmeta.meta_key = \'apecard\'
AND wpostmeta.meta_value = \'on\'
AND wpterms.term_id = \'143\'
AND wposts.post_status = \'publish\'
AND wposts.post_type = \'locali\'
ORDER BY wposts.post_date DESC ";
.....
结果显示在分类法的每个类别中都有meta\\u key=\'apecard\'的所有帖子。但我想只在term\\u id=143的类别中显示帖子。谢谢你!!!
SO网友:Rajeev Vyas
$args = array(
\'post_type\' => \'locali\',
\'meta_query\' => array(
array(
\'key\' => \'apecard\',
\'value\' => \'on\',
)
),
\'tax_query\' => array(
array(
\'taxonomy\' => \'yourtaxonomy\',
\'field\' => \'id\',
\'terms\' => array(\'143\')
)
)
);
$postslist = get_posts( $args );