0

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() ) :
5
  • Please include relevant code in your question otherwise it's hard to identify the problem. Commented Dec 27, 2014 at 23:10
  • Updated with code example from underscores
    – cristovaov
    Commented Dec 27, 2014 at 23:28
  • 1
    That's the default function from underscore. Please add the code that you've added to the theme, like the pre_get_posts function or the loop you're using. Commented Dec 28, 2014 at 0:04
  • Yes, sorry - re-edited my post again.
    – cristovaov
    Commented Dec 28, 2014 at 12:08
  • I have found the answer to my problem, the 'themeslug_posted_on' works as expected. Editing my question with the solution. Cheers~
    – cristovaov
    Commented Dec 28, 2014 at 15:43

1 Answer 1

1

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() ) :
1
  • This is also located in template-tags.php
    – rockmandew
    Commented Apr 29, 2016 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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