【发布时间】:2014-03-27 19:07:45
【问题描述】:
我知道如何获取所有 Wordpress 术语,但我需要结果的“过滤”版本。是否可以获得 Wordpress 查询结果中的所有术语?我在这里有这个查询:
<?php
$args=array(
'post_type' => 'gw_activity',
'post_status' => 'publish',
'orderby' => 'date',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'activity_category',
'value' => 'mindful_life',
'compare' => '='
)
),
'posts_per_page' => 10
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
$all_terms = array();
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php $terms = wp_get_post_terms( $my_query->post->ID, array( 'gw_activity_tag' ) ); ?>
<?php
foreach ( $terms as $term ) {
$all_terms[] = $term->name;
}
?>
<?php endwhile; }
wp_reset_query();
?>
<!-- End Custom Query -->
<?php
$unique_terms = array_unique( $all_terms );
$result = array_unique($unique_terms);
foreach ($result as $value) {
echo $value . '<br />';
}
?>
但我不知道如何运行查询并在其中添加“Where”子句,就像使用 MySQL 一样。任何帮助/建议,甚至指出我正确的方向都将不胜感激。我卡住了
【问题讨论】: