1

カスタム投稿タイプ「リソース」内にあるすべてのタグを取得しようとしています。

問題は、私がループの外にいて、機能をカスタム投稿タイプで動作させる方法を見つけるのに苦労していることです。

「resource_category」としてもカテゴリを設定しています

私の現在のコードは次のとおりです。

$tax = 'post_tag';
$terms = get_terms( $tax );
$count = count( $terms );

if ( $count > 0 ): ?>
    <div class="post-tags">
    <?php
    foreach ( $terms as $term ) {
        $term_link = get_term_link( $term, $tax );
        echo '<a href="' . $term_link . '" class="tax-filter" title="' . $term->slug . '">' . $term->name . '</a> ';
    } ?>
    </div>
<?php endif;

誰でも助けることができますか?

4

3 に答える 3

-3
$args = array(
 'type' => 'resource',
 'orderby' => 'name',
 'order' => 'ASC'
);
$categories = get_categories($args);

foreach($categories as $category) { 
 echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
}
于 2015-03-24T10:39:48.000 に答える