首页 > 解决方案 > 显示特定自定义分类类型的帖子

问题描述

我有一个custom taxonomy被叫Topics分配给custom post type被叫blog

Topics目前看起来像这样:

在此处输入图像描述

现在,在 上/blog,我有一个select如下所示的过滤器:

// submit form on select change
$('.blogFilter .blogFilter__form').on('change', function() {
  $(this).submit();
});
<?php
$terms = get_terms(
  array(
    'taxonomy' => 'Topics',
    'hide_empty' => true,
  )
); ?>

<form class="blogFilter__form" role="search" action="<?php echo site_url('/blog/'); ?>" method="get">
  <select class="globalFilter">
    <option class="globalFilter__option" value="">Topics</option>
    <?php
  foreach ( $terms as $term ) {
    $term_link = get_term_link( $term );
    $term_name = get_term( $term )->name;?>
      <option class="globalFilter__option" value="<?php echo $term_link; ?>">
        <?php echo $term_name; ?>
      </option>
      <?php } ?>
  </select>
</form>

Idea being that when the selectoption changes, it will submit the form and display posts that matches that Topic. 即,如果我News从下拉列表中选择,它只会显示带有topicof 的帖子News

Currently, when choose News, it shows me all posts.

我遇到的最接近的解决方案是标签模板。但这似乎不适用于custom taxonomies.

我想要实现的是以下经验:

标签: phpwordpresscustom-post-typecustom-taxonomy

解决方案


推荐阅读