0

I registered a custom post type ("movie") with tags and categories. Now, I'm able to filter and search for the custom post with these tags and categories, so I know they're present and working, but they're not showing up on the custom posts.

This is the code for the meta data to show up.

<?php
if( !myThemes::get( 'show-bottom-meta' ) ){
return;
}
if( is_singular( 'post' ) && ( has_category( ) || has_tag() ) ){
?>
<div class="post-meta-terms">
<?php

if( is_singular( 'post' ) && has_category( ) ){
echo '<div class="post-meta-categories">';
echo '<strong><i class="icon-list"></i> ' . __( 'Categories' , 'myThemes' ) . '</strong>: ';
the_category( ' ' );
echo '</div>';
}

if( is_singular( 'post' ) && has_tag() ){
echo '<div class="post-meta-tags">';
echo '<strong><i class="icon-tags"></i> ' . __( 'Post Tags' , 'myThemes' ) . '</strong>: ';
the_tags( ' ' , ' ' , ' ' );
echo '</div>';
}
?>
</div>
<?php
}
?>

This has only "post" so I added "movies" to make it show the meta data for movies as well, like this:

<?php
    if( !myThemes::get( 'show-bottom-meta' ) ){
        return;
    }
    if( is_singular( 'post', 'movie' ) && ( has_category( ) || has_tag() ) ){
?>
        <div class="post-meta-terms">
            <?php

                if( is_singular( 'post', 'movie' ) && has_category( ) ){
                    echo '<div class="post-meta-categories">';
                    echo '<strong><i class="icon-list"></i> ' . __( 'Categories' , 'myThemes' ) . '</strong>: ';
                    the_category( ' ' );
                    echo '</div>';
                }

                if( is_singular( 'post', 'movie' ) && has_tag() ){
                    echo '<div class="post-meta-tags">';
                    echo '<strong><i class="icon-tags"></i> ' . __( 'Post Tags' , 'myThemes' ) . '</strong>: ';
                    the_tags( ' ' , ' ' , ' ' );
                    echo '</div>';
                }
            ?>
        </div>
<?php
    }
?>

But it isn't working. I checked this post (link) but it looks like they follow the same logic, so I'm not sure what's wrong here.

Any help greatly appreciated. Thanks!

2

Your argument for is_singular() is wrong

It should be an array

is_singular(array('post','movie'))

You can read more about the argument passed from this link here

  • 1
    Note also that you can call is_singular() with no post types defined, ensuring that the function will return true for a singular post no matter the post type. – David Gard Dec 24 '14 at 11:20
  • Thanks, David and Karun! The fix was so easy, I'm embarrassed I didn't see it myself! Thanks again! – cydb Dec 25 '14 at 11:55
0

The problem is in second side of condition

... && ( has_category( ) || has_tag() ) { ...

try change with

... && has_term( null , 'collections' , $post -> ID ) ){ ...

where "collections" is slug name for registered custom terms ( custom tags and categories )

also I want recommend you to use other slug name for custom tags and categories for your custom posts eg: movie-tags, movie-categories

  • and also is need to change function the_category() and the_tags() with the_terms( $post -> ID , 'collections' , null , '' ); OR the_terms( $post -> ID , 'movie-categories' , null , '' ); AND the_terms( $post -> ID , 'movie-tags' , null , '' ); – myThem.es Feb 10 '15 at 8:06
  • File an edit if you want to add more to your answer. – Gabriel Feb 10 '15 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.