I have a all my custom post types list together in blog format. What I’m trying to do is echo the post type name on each post.
I tried this:
get_post_type_object('post');
echo $obj->labels->singular_name;
But it just displayed “Post” for everything instead of the custom post type name
If you are within The Loop, try:
Does this work for you?
Inside the loop you already have a
$post
object available to you, you don’t need to callget_post_type
or any other functions, this should do the trick.Or if you like the idea of calling
get_post_type
you can make the task easier for the function by passing it the post object you have(so it doesn’t need to go fetch the post, just to extract one property from it).Else,
get_post_type
will needlessly callget_post
to fetch the post object (an object you already have available to you nonetheless).Hope that helps..
Reading the docs at http://codex.wordpress.org/Function_Reference/get_post_type_object
you must pass it the custom post type as argument!
Try with: