0

我的网站上有以下代码,它输出“下载”帖子类型的类别列表。我希望排除某些类别出现在输出中,我该怎么做?

<?php
/**
 * Generate list of EDD categories to browse
 */
$args = array(
  'orderby' => 'name',
  'hierarchical' => 1,
  'style' => 'none',
  'taxonomy' => 'download_category',
  'hide_empty' => 0,
  'depth' => 1,
  'title_li' => '',
  // 'parent' => 0
);
$categories = get_categories( $args );

if ( $categories ) {
  ?>
<div class="search-cats">
  <div class="search-cat-text">
    <?php _e( 'Browse by category: ', 'checkout' ); ?>
  </div>
  <nav>
    <?php
    /**
     * Generate list of EDD category links
     */
    foreach ( $categories as $category ) {
      $link = get_term_link( $category, 'download_category' );
      echo '<a href="' . esc_url( $link ) . '" rel="tag">' . $category->name . '</a>';
    }
    ?>
  </nav>
</div>
<?php } ?>
4

1 回答 1

0

您要查找的参数中的参数exclude请参阅https://developer.wordpress.org/reference/classes/wp_term_query/__construct/以获取有关可用于此类查询的参数的详细信息。

$args = array(
  'orderby' => 'name',
  'hierarchical' => 1,
  'style' => 'none',
  'taxonomy' => 'download_category',
  'hide_empty' => 0,
  'depth' => 1,
  'title_li' => '',
  'exclude' => 24,21 /* Array or comma/space-separated string of term IDs 
                        to exclude. If $include is non-empty, $exclude is
                        ignored. Default empty array. */
);
$categories = get_categories( $args );
于 2020-10-19T09:41:36.143 回答