我已经为自定义帖子类型“Movies”创建了一个自定义分类列表,下面是部分代码:
public function init_post_type()
{
// get label
$labels = array(
\'name\' => __(\'Movies\', \'tmdb\'),
\'singular_name\' => __(\'movie\', \'tmdb\'),
\'add_new\' => __(\'Add new movie\', \'tmdb\'),
\'add_new_item\' => __(\'Add new movie\', \'tmdb\'),
\'edit_item\' => __(\'Edit movie\', \'tmdb\'),
\'new_item\' => __(\'New movie\', \'tmdb\'),
\'view_item\' => __(\'View movie\', \'tmdb\'),
\'search_items\' => __(\'Search into movies\', \'tmdb\'),
\'not_found\' => __(\'No movies found\', \'tmdb\'),
\'not_found_in_trash\' => __(\'No movies in trash\', \'tmdb\')
);
// start formationg arguments
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'has_archive\' => true,
\'query_var\' => true,
\'rewrite\' => true,
\'menu_icon\' => TMDB_asset_url( \'images/icon.png\' ),
\'capability_type\' => \'post\',
\'show_in_menu\' => true,
\'supports\' => array( \'title\', \'editor\', \'thumbnail\', \'comments\' )
);
register_post_type( \'movies\', $args );
// add taxonomies for this post type
$this->init_taxonomies();
add_action( \'admin_head\', array( $this, \'add_32px_icon\' ) );
// add meta boxes to "movies" post type
add_action(\'admin_menu\', array($this, \'add_to_menu_metabox\'));
// change the layout of movies list
add_filter(\'manage_edit-movies_columns\', array( $this, \'movies_edit_columns\' ) );
add_action(\'manage_posts_custom_column\', array( $this, \'movies_posts_columns\' ), 10, 2);
}
// Initialize New Taxonomy Labels for the questions custom post type
public function init_taxonomies()
{
$labels = array(
\'name\' => __( \'Franchises\', \'tmdb\' ),
\'singular_name\' => __( \'franchise\', \'tmdb\' ),
\'search_items\' => __( \'Search franchise Types\', \'tmdb\' ),
\'all_items\' => __( \'All franchise Types\', \'tmdb\' ),
\'parent_item\' => __( \'Parent franchise Types\', \'tmdb\' ),
\'parent_item_colon\' => __( \'Parent franchise Types:\', \'tmdb\' ),
\'edit_item\' => __( \'Edit franchise Types\', \'tmdb\' ),
\'update_item\' => __( \'Update franchise Type\', \'tmdb\' ),
\'add_new_item\' => __( \'Add New franchise Type\', \'tmdb\' ),
\'new_item_name\' => __( \'New franchise Type\', \'tmdb\' ),
);
// register taxonomy to hold our genre
register_taxonomy(
\'franchise\',
array(\'movies\'),
array(
\'hierarchical\' => true,
\'query_var\' => true,
\'show_in_nav_menus\' => true,
\'labels\' => $labels,
\'show_tagcloud\' => false
)
);
我使用以下代码显示这些自定义分类:
<?php if( isset($the_movie[\'_tagline\']) ) { ?>
<li><span><?php esc_attr_e(\'Tagline\', \'tmdb\'); ?>:</span> <?php echo $the_movie[\'_tagline\'];?></li>
<?php } ?>
<?php if( isset($the_movie[\'_homepage\']) ) { ?>
<li><span><?php esc_attr_e(\'Film website\', \'tmdb\'); ?>:</span> <a href="<?php echo $the_movie[\'_homepage\'];?>" target="_blank"><?php echo $the_movie[\'_homepage\'];?></a></li>
<?php the_terms( $post->ID, \'regisseur\', \'Regisseur: \', \', \', \' \' ); ?><br>
<?php the_terms( $post->ID, \'land\', \'Land: \', \', \', \' \' ); ?><br>
<?php the_terms( $post->ID, \'subgenre\', \'Subgenres: \', \', \', \' \' ); ?><br>
<?php the_terms( $post->ID, \'stijl\', \'Stijl: \', \', \', \' \' ); ?><br>
<?php the_terms( $post->ID, \'streaming\', \'Te zien bij: \', \', \', \' \' ); ?><br>
<?php the_terms( $post->ID, \'plot\', \'Plot: \', \', \', \' \' ); ?><br>
<?php } ?>
我知道我可能应该使用get\\u the\\u term\\u list,但它还不能工作。我现在的问题是自定义分类法的最后一个列表。他们表现得很好,除了少数帖子,这对我来说毫无意义。
这里有一个链接,它工作正常:
Link to post that works
这里有一个链接,指向分类法未显示的位置:
Link to post not showing custom taxonomies
我已经尝试过一些事情:
确保填写问题帖子的所有自定义分类字段并保存帖子使用插件“show post categories”来尝试显示自定义分类法,我得到了相同的结果,大多数都很好,有些没有,它们是相同的删除并重新添加了该帖子,结果相同,没有显示分类法所以我在这里不知所措。这根本没有道理。这是代码问题吗?数据库问题?Wordpress搞糟了?我们将非常感谢您的帮助。