[Resolved] Custom Post Type not showing Author, Date and other Meta Data

Home Forums Support [Resolved] Custom Post Type not showing Author, Date and other Meta Data

Home Forums Support Custom Post Type not showing Author, Date and other Meta Data

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #333793
    Paul

    Hi Guys,

    I have been through the forum thoroughly and can’t get Author and other meta data to show.

    It all shows on my normal blog page but not on my custom post type page.

    1.) I’m aware that by default on Custom Post Types meta data doesn’t show

    2.) I’ve added the code recommended on another post to my functions.php and its still not working:

    if ( ! function_exists( ‘generate_post_meta’ ) ) :
    /**
    * Build the post meta
    *
    * @since 1.3.29
    */
    add_action( ‘generate_after_entry_title’, ‘generate_post_meta’ );
    function generate_post_meta()
    {
    if ( ‘post’ == get_post_type() || ‘review’ == get_post_type() ) : ?>

    <!– .entry-meta –>
    <?php endif;
    }
    endif;

    if ( ! function_exists( ‘generate_footer_meta’ ) ) :
    /**
    * Build the footer post meta
    *
    * @since 1.3.30
    */
    add_action( ‘generate_after_entry_content’, ‘generate_footer_meta’ );
    function generate_footer_meta()
    {
    if ( ‘post’ == get_post_type() || ‘review’ == get_post_type() ) : ?>
    <footer class=”entry-meta”>
    <?php generate_entry_meta(); ?>
    <?php if ( is_single() ) generate_content_nav( ‘nav-below’ ); ?>
    </footer><!– .entry-meta –>
    <?php endif;
    }
    endif;

    Can you please help

    Cheers

    Paul

    #333820
    Tom
    Lead Developer
    Lead Developer

    I would do this:

    add_action( 'after_setup_theme','tu_remove_entry_meta' );
    function tu_remove_entry_meta() {
    	remove_action( 'generate_after_entry_content', 'generate_footer_meta' );
    	remove_action( 'generate_after_entry_title', 'generate_post_meta' );
    }
    
    add_action( 'generate_after_entry_title', 'tu_cpt_post_meta' );
    function tu_cpt_post_meta()
    {
    	if ( 'post' == get_post_type() || 'review' == get_post_type() ) : ?>
    		<div class="entry-meta">
    			<?php generate_posted_on(); ?>
    		</div><!-- .entry-meta -->
    	<?php endif;
    }
    
    add_action( 'generate_after_entry_content', 'tu_cpt_footer_meta' );
    function tu_cpt_footer_meta()
    {
    	if ( 'post' == get_post_type() || 'review' == get_post_type() ) : ?>
    		<footer class="entry-meta">
    			<?php generate_entry_meta(); ?>
    			<?php if ( is_single() ) generate_content_nav( 'nav-below' ); ?>
    		</footer><!-- .entry-meta -->
    	<?php endif;
    }

    This of course assumes that your CPT is named: review

    #333829
    Paul

    All works thanks heaps.

    #333831
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

    #333837
    Paul

    Now i’m trying to enable Co-Authors Plus which requires some changes. See:

    https://generatepress.com/forums/topic/co-author-plus/

    And it won’t work on the Custom Post Type. I added the code above to Template Tags in the child theme.

    How do I get that to work with the code you added above?

    Thanks heaps

    #334057
    Tom
    Lead Developer
    Lead Developer
    #334231
    Paul

    Excellent, We’re almost there.

    Only thing now with that code change is on both my blog and custom post type. Author and Date now look like this:

    June 13, 2017Melisa Grigg

    (It’s lost the space and the “by”)

    Instead of:

    June 13, 2017 by Melisa Grigg

    Thanks heaps for all your help

    #334303
    Tom
    Lead Developer
    Lead Developer

    Just updated the code. Can you try again?

    #334313
    Paul

    It was pretty good. Was just missing a space before the b on “by”

    If you want to update your code.

    Thanks for your help

    #334544
    Tom
    Lead Developer
    Lead Developer

    Updated. Thanks! 🙂

    #496259
    Miroslav

    Where do you put that code, Tom? And, why doesn’t the || 'review' == get_post_type() solution work?

    #496877
    Tom
    Lead Developer
    Lead Developer

    PHP can be added like this: https://docs.generatepress.com/article/adding-php/

    That solution should work if the currently viewed post type is: review

    #497347
    Miroslav

    Thanks, I thought it was supposed to be placed in the inc/structure/post-meta.php file (of my child theme).

    #497471
    Tom
    Lead Developer
    Lead Developer

    Glad I could help 🙂

    #506006
    Paul

    Hi Tom,

    Just need to add categories and tags to custom post type as they aren’t showing by default. I’m close I just dont know how to only show the custom taxonomies below only if there is one for the post. e.g. It’s currently showing an icon even if the article doesn’t have a category.

    Got this code:

    add_action( 'after_setup_theme','tu_remove_entry_meta' );
    function tu_remove_entry_meta() {
    	remove_action( 'generate_after_entry_content', 'generate_footer_meta' );
    	remove_action( 'generate_after_entry_title', 'generate_post_meta' );
    }
    
    add_action( 'generate_after_entry_title', 'tu_cpt_post_meta' );
    function tu_cpt_post_meta()
    {
    	if ( 'post' == get_post_type() || 'club' == get_post_type() ) : ?>
    		<div class="entry-meta">
    			<?php generate_posted_on(); ?>
    		</div><!-- .entry-meta -->
    	<?php endif;
    }
    
    add_action( 'generate_after_entry_content', 'tu_cpt_footer_meta' );
    function tu_cpt_footer_meta()
    {
    	if ( 'post' == get_post_type() || 'club' == get_post_type() ) : ?>
    		<footer class="entry-meta">
    			<?php generate_entry_meta(); ?>
    				<span class="cat-links"><?php echo get_the_term_list( $post->ID, 'club_category', $before = '', ', ' ); ?></span>
    				<span class="tags-links"><?php echo get_the_term_list( $post->ID, 'club_tags', $before = '', ', ' ); ?></span>
    
    			<?php if ( is_single() ) generate_content_nav( 'nav-below' ); ?>
    		</footer><!-- .entry-meta -->
    	<?php endif;
    }
Viewing 15 posts - 1 through 15 (of 18 total)
  • You must be logged in to reply to this topic.