最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Custom taxonomies not displaying in some custom posts

programmeradmin4浏览0评论

I have created a list of custom taxonomies for custom post type 'Movies', here's part of the code:

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
            )
        );

I am displaying those custom taxonomies with this code:

<?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 } ?>

I know i should probably use get_the_term_list, but dit not get that working yet. My problem now lies in the last list of custom taxonomies. They show fine, except on only a few posts, which makes no sense to me.

Here's a link to it working fine:

Link to post that works

And here's a link to where to taxonomies do not show up:

Link to post not showing custom taxonomies

Some things i already tried:

  • Make sure all custom taxonomy fields for the problem post are filled and posts is saved.
  • Use plugin 'show post categories' to try and show the custom taxonomies, i get the same results, most work fine, some do not, they are the same ones.
  • Deleted and re-added the post, with the same result, taxonomies not showing.

So i am at a loss here. It just does not make sense. Is it a code problem? A database problem? Wordpress messing up? Any help here would be greatly appreciated.

I have created a list of custom taxonomies for custom post type 'Movies', here's part of the code:

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
            )
        );

I am displaying those custom taxonomies with this code:

<?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 } ?>

I know i should probably use get_the_term_list, but dit not get that working yet. My problem now lies in the last list of custom taxonomies. They show fine, except on only a few posts, which makes no sense to me.

Here's a link to it working fine:

Link to post that works

And here's a link to where to taxonomies do not show up:

Link to post not showing custom taxonomies

Some things i already tried:

  • Make sure all custom taxonomy fields for the problem post are filled and posts is saved.
  • Use plugin 'show post categories' to try and show the custom taxonomies, i get the same results, most work fine, some do not, they are the same ones.
  • Deleted and re-added the post, with the same result, taxonomies not showing.

So i am at a loss here. It just does not make sense. Is it a code problem? A database problem? Wordpress messing up? Any help here would be greatly appreciated.

Share Improve this question asked Apr 16, 2020 at 8:57 njinoknjinok 11 bronze badge 3
  • Your code is only registering one taxonomy: franchise. Where are the others registered? – Jacob Peattie Commented Apr 16, 2020 at 12:14
  • They are listed the same way, but because it is basically all the some code with only the names changed i did not list it to avoid making the code too long. They are there and they work. Thank you for looking at my problem. Hope you have a good suggestion. – njinok Commented Apr 16, 2020 at 12:17
  • Where is $post coming from? – Jacob Peattie Commented Apr 16, 2020 at 13:12
Add a comment  | 

1 Answer 1

Reset to default 0

I managed to get it working. This is the code i used:


<?php echo get_the_term_list( $post->ID, 'regisseur', 'Regisseur: ', ', ', '' ); ?>

All custom taxonomies show fine now. Only thing i need now is to not show a blank line when a custom taxonomy has no values. If anybody has any ideas?

发布评论

评论列表(0)

  1. 暂无评论