Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Trying to use is_singular()

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #244949
    Steven
    Participant

    So I have a search results page I’m working on.

    I have a number of custom post types that I’d like to differentiate in the list of results from regular blog posts.

    What I tried to do was something like this:

    if( is_singular( 'post' ) ) :
        // show meta data for things like date, author and taxonomy
    else :
        // show something like "custom post type name"
    endif;
    

    The idea here is that is_singular( 'post' ) returns true if it’s a standard post, and returns false if it’s a custom post type.

    The problem I’m experiencing is that it is always returning false, even for my regular, old blog posts.

    What am I doing wrong or completely misunderstanding?2

    Thanks!

    #244970
    Atelierbram
    Participant

    Can’t really explain it properly, but what works for me here is get_post_type.

    So let’s say we have a custom post type named “contacts”

    if (  'contacts' == get_post_type()  ) :
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.