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()
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
// show something like "custom post type name"
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.
is_singular( 'post' )
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
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() ) :