0

WordPressサイトでカスタム投稿タイプを作成しました。そのカスタム投稿タイプに多くの投稿が追加されました。

そのカスタム投稿タイプの各投稿に割り当てられたすべてのカテゴリを表示したい。私を助けてください。ありがとう...

4

4 に答える 4

2

あなたが試すことができます:

$terms = get_the_terms($post->ID, 'your_taxonomy_name');

http://codex.wordpress.org/Function_Reference/get_the_terms

ただし、最初にCPTの分類法を設定する必要があります。

http://codex.wordpress.org/Function_Reference/register_taxonomy

于 2013-05-10T15:10:34.553 に答える
1

以下のコードを試すことができます

foreach ( get_posts( 'numberposts=-1') as $post ) {

            wp_set_object_terms($post_id, 'category_name', 'category');
    }
于 2013-05-10T13:45:09.967 に答える
1

Wordpressの機能を使用する:

has_term:http ://codex.wordpress.org/Function_Reference/has_term

およびget_the_terms:http ://codex.wordpress.org/Function_Reference/get_the_terms

has_term()を使用することが重要です。これにより、カスタム分類法を使用しない投稿でエラーが発生しなくなります。

get_the_terms()は、現在の投稿IDのすべての用語を取得します。これは、ループ内で使用してください。


例:

<ul class="post-entry-meta">

<?php if( has_term('','your taxonomy' ))

{

$terms = get_the_terms( $post->ID , 'your taxonomy' ); 

foreach ( $terms as $term )

{echo '<li class="taxonomy-list">', $term->name , '</li>' ;}

}?> 

</ul>
于 2013-10-04T17:59:46.237 に答える
1
<?php
$custom_post_taxonomies = get_object_taxonomies('your_taxonomy_name');

if(count($custom_post_taxonomies) > 0)
{
 foreach($customPostTaxonomies as $tax)
 {
     $args = array(
          'orderby' => 'name',
          'show_count' => 0,
          'pad_counts' => 0,
          'hierarchical' => 0,
          'taxonomy' => $tax,
          'title_li' => ''
        );

     wp_list_categories( $args );
 }
}
?>

「your_taxonomy_name」を分類法名に置き換えてください。それはうまく機能しています。

于 2014-07-08T13:27:56.977 に答える