Kaleb.G
Member
Posted 2 years ago #
I've searched all over trying to find a simple function that will let me know if one of the posts returned from inside the loop is either a WordPress "page" or a "post". is_page() doesn't work, because that only works if the entire page you're viewing is the content of a WordPress "page".
What I'm trying to do exactly is this: My search results page displays both "pages" and "posts", which is good. However, each of the "pages" shows that it's posted in the "Uncategorized" category. Instead of saying that, I want a function to determine if it's a "page" type, and have it show some different text rather than the category list.
Can someone please help me? Thanks in advance.
If it's inside the Loop, try:
<?php if($post->post_type == 'post') :?>
[ do stuff ]
<?php endif;?>
Kaleb.G
Member
Posted 2 years ago #
Ha, that worked! I think this would be good information to add to the Codex. Or if it's in there, make it easier to find. Anyway, this is exactly what I needed. Thank you!
Kaleb.G
Member
Posted 2 years ago #
alchymyth, I already knew what the database schema is. I just didn't know I could access the field by using $post->field_name. I haven't seen that explained anywhere in the Codex.
you are right - the codex is great if one knows what to look for.
it is not the best instruction manual.
Kaleb.G
Member
Posted 2 years ago #
Agreed. Hopefully the people who have access to work on it can improve on this aspect.
Kaleb.G
Member
Posted 2 years ago #
I'm pretty sure I had tried that function and it didn't work for me.
Then again I may not even been searching the Codex for "post type". I was searching for stuff like "page or post".