Question

In underscores I can get my custom post type just fine with pre get posts along regular blog posts. However the date published and author does not display. How can I modify my template tag (themeslug_posted_on) to show them as well?

My pre get posts filter:

add_filter( 'pre_get_posts', 'get_my_cpt' );
function get_my_cpt( $query ) {
    if ( is_archive() || is_search() || is_home() && $query->is_main_query() )
        $query->set( 'post_type', array( 'post', 'my_cpt' ) );
    return $query;
}

The underscores I'd like to modify:

if ( ! function_exists( '_s_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
*/
function _s_posted_on() {
    $time_string = '%2$s';
    if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
        $time_string = '%2$s%4$s';
    }
    $time_string = sprintf( $time_string,
        esc_attr( get_the_date( 'c' ) ),
        esc_html( get_the_date() ),
        esc_attr( get_the_modified_date( 'c' ) ),
        esc_html( get_the_modified_date() )
    );
    $posted_on = sprintf(
        _x( 'Posted on %s', 'post date', '_s' ),
        '' . $time_string . ''
    );
    $byline = sprintf(
        _x( 'by %s', 'post author', '_s' ),
        '' . esc_html( get_the_author() ) . ''
    );
    echo '' . $posted_on . ' ' . $byline . '';
}
endif;

Answer: I was looking in the wrong place. The answer lays in the 'content.php' file of underscores. The expected result displayed is by adding my cpt to the conditional,like so :

if ( 'post' || 'my_cpt' == get_post_type() ) :
Was it helpful?

Solution

I was looking in the wrong place. The answer lays in the 'content.php' file of underscores. The expected result displayed is by adding my cpt to the conditional,like so :

if ( 'post' || 'my_cpt' == get_post_type() ) :
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top