我正在尝试为自定义帖子类型页面构建过滤器。自定义帖子类型有一个元框,允许输入不同的作者。
我使用get\\u post\\u meta以如下方式下拉显示帖子名称:
/*Get the Authors*/
$list_authors = array(
\'post_type\' => array(\'publications\'),
);
$authors = array();
$query_authors = new WP_Query( $list_authors );
if ( $query_authors->have_posts() ) :
while ( $query_authors->have_posts() ) : $query_authors->the_post();
$author = get_post_meta(get_the_id(), \'cl_pub_authors\', true);
if(!in_array($author, $authors)){
$authors[] = $author;
}
endwhile;
wp_reset_postdata();
endif;
foreach( $authors as $author ):
?>
<option value="<?php echo $author;?>"><?php echo $author;?></option>
<?php endforeach; ?>
问题是有些值被分组在一起,并用逗号分隔。我需要将字段中的每个值作为单独的值,并避免重复。