admin管理员组文章数量:1410674
I have an archive page that I am building multi-filtering for. The archive page lists paginated results from a custom post type, and there are 3000 posts within it.
I would like to be able to filter this post type by two taxonomies, but importantly the page should only show an option to filter by one of the categories within each taxonomy if there is a result.
The below code works, but is extremely slow and inefficient, taking five seconds to return results. How can I improve this or are there alternative solutions to implement multi-filtering?
$tax_args = array(
'post_type' => 'output',
'post_status' => 'publish',
'posts_per_page' => '2000',
);
$the_query = new WP_Query($tax_args);
$all_terms = array();
if($the_query->have_posts()):
while($the_query->have_posts()):
$the_query->the_post();
$terms = wp_get_post_terms($the_query->post->ID, array('library-topics', 'library-types'));
foreach ( $terms as $term ) {
$all_terms[] = $term->name;
}
endwhile;
$result = array_unique($all_terms);
foreach ($result as $term){
echo $term . '<br/>';
}
endif;
wp_reset_postdata();
本文标签: filtersList all categories that have results in a query
版权声明:本文标题:filters - List all categories that have results in a query 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744990923a2636380.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论