admin管理员组文章数量:1327802
I'm querying custom posts taken from a custom metabox where you pick which posts to display to be used as criteria for filtering. How do I avoid duplicates?
Current code (displays all authors - the custom post type selected in metabox - but if more than one post selected the same, then it is repeated.. need one instance only for each):
$list_authors = array(
'post_type' => array('publications'),
);
$query_authors = new WP_Query( $list_authors );
if ( $query_authors->have_posts() ) :
while ( $query_authors->have_posts() ) : $query_authors->the_post();
/*Get the Authors*/
$unique_authors = array();
$author_ids = get_post_meta(get_the_id(), 'cl_pub_auth', true);
$author_ids = ( $author_ids && is_array( $author_ids ) ) ? array_map( 'intval', $author_ids ) : array();
if ( $author_ids ) {
foreach ( $author_ids as $author_id ) {
if(!in_array($author_id, $unique_authors)):
$author_id[] = $author_id;
endif;
$authors[] = get_post( $author_id );
}
}
endwhile;
wp_reset_postdata();
endif;
本文标签: How to avoid duplicate posts queried from custom meta
版权声明:本文标题:How to avoid duplicate posts queried from custom meta? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742234382a2437802.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论