我必须制作一个搜索表单,在其中我必须按自定义帖子类型的状态填充选择。其中一些具有相同的状态,然后我想分组以获得一个干净的状态选择列表。我已经这样做了:
<?php
function query_group_by_filter($groupby){
global $wpdb;
return $wpdb->postmeta.".meta_key = 'state'";
}
?>
<?php add_filter('posts_groupby', 'query_group_by_filter'); ?>
<?php $states = new WP_Query(array('post_type' => 'observatoire')); ?>
<?php remove_filter('posts_groupby', 'query_group_by_filter'); ?>
<select id="" class="" name="siege_pays" >
<option value=""></option>
<?php
while ( $states->have_posts() ) : $states->the_post();
echo "<option value=".get_field_object('state').">".get_field_object('state')."</option>";
endwhile;
?>
</select>
结果查询不起作用..请帮助:)
'SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'observatoire' AND ((wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') OR wp_posts.post_status = 'private') GROUP BY wp_postmeta.meta_key = 'siege_pays' ORDER BY wp_posts.post_date DESC LIMIT 0, 10'