WordPressサイトでカスタム投稿タイプを作成しました。そのカスタム投稿タイプに多くの投稿が追加されました。
そのカスタム投稿タイプの各投稿に割り当てられたすべてのカテゴリを表示したい。私を助けてください。ありがとう...
WordPressサイトでカスタム投稿タイプを作成しました。そのカスタム投稿タイプに多くの投稿が追加されました。
そのカスタム投稿タイプの各投稿に割り当てられたすべてのカテゴリを表示したい。私を助けてください。ありがとう...
あなたが試すことができます:
$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
以下のコードを試すことができます
foreach ( get_posts( 'numberposts=-1') as $post ) {
wp_set_object_terms($post_id, 'category_name', 'category');
}
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>
<?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」を分類法名に置き換えてください。それはうまく機能しています。