1

I have a created a custom post type but on category archive pages the post meta information is not displayed.

This is the code used to display the post meta:

<?php if ( 'post' === get_post_type() ) codilight_meta_1();?>

And this is the above function's code:

function codilight_meta_1() {
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
    $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
}

$time_string = sprintf( $time_string,
    esc_attr( get_the_date( 'c' ) ),
    esc_html( get_the_date() )
);

$posted_on = sprintf(
    esc_html_x( '%s', 'post date', 'codilight' ),
    '<span class="entry-date">' . $time_string . '</span>'
);
$byline = sprintf(
    esc_html_x( '%s', 'post author', 'codilight' ),
    '<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
);

echo '<div class="entry-meta entry-meta-1">';

    echo $byline.$posted_on;
    if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
        echo '<span class="comments-link">';
        echo '<i class="fa fa-comments-o"></i>';
        comments_popup_link( '0', '1', '%' );
        echo '</span>';
    }

echo '</div>';
}
  • 1
    'post' is not a custom post type. – birgire Oct 30 '16 at 11:30
  • if you put the code of codilight_meta_1(), we'll able to tell you if you need to echo or not the result of your function. And as @birgire told you if you create a cpt, you code will not shown this condition (based on post). – Benoti Oct 30 '16 at 12:27
  • Yes, I realize 'post' is not a custom post type but i wasn't sure what changes needed to be made. – jrcollins Oct 30 '16 at 20:56
  • @Benoti I added the full code. Any ideas? – jrcollins Nov 1 '16 at 21:04
  • Yes "post" is the standard post-type, if you create a new one, you need to replace "post" with the post-type you need. – Benoti Nov 2 '16 at 9:03
4
+50

Just change,

<?php if ( 'post' === get_post_type() ) codilight_meta_1();?>

to

<?php if ( 'post' === get_post_type() || 'reviews' === get_post_type()) codilight_meta_1();?>
  • 1
    Or use in_array like this: if ( in_array( get_post_type(), array( 'post', 'reviews' ) ) ) codilight_meta_1(); – Jory Hogeveen Nov 5 '16 at 17:38
  • Thanks, the first answer you gave is working. I did try something like that before but I was getting an error. don't know what I was doing wrong but at least it's working now. Thanks for your help. – jrcollins Nov 5 '16 at 23:06

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.