Archived topic
Custom Post Type not showing Author, Date and other Meta Data
17 replies · Started by Paul on June 14, 2017
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
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
All works thanks heaps.
You're welcome :)
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
Hi Paul,
Try this instead: https://gist.github.com/generatepress/b5bb793b79c2274aee4e
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
Just updated the code. Can you try again?
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
Updated. Thanks! :)
Where do you put that code, Tom? And, why doesn't the || 'review' == get_post_type() solution work?
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
Thanks, I thought it was supposed to be placed in the inc/structure/post-meta.php file (of my child theme).
Glad I could help :)
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;
}