WordPress.org

Ready to get started?Download WordPress

Forums

Search results template (2 posts)

  1. privatestorm
    Member
    Posted 6 years ago #

    I'm trying to customize my search results template and am having trouble with one detail. For all of the results I have it set to display the category and other misc details. This is great for posts, but I don't want to display that info for pages (i'm using a plugin to search both pages & posts).

    In the loop I need some kind of if/else statement to detect whether that item is a post or page. I've tried is_page() but that doesn't work. What is the correct syntax to use to detect whether the post_type is page or post?

    I've also tried this but it doesn't work:

    <?php if ($post_type = 'page') : ?>
    display this
    <?php else : ?>
    display something else
    <?php endif; ?>
  2. jeremyduffy
    Member
    Posted 6 years ago #

    You tried is_page and it didn't work? You could go manual and check the post by id and pull that variable using wpdb->get_var

Topic Closed

This topic has been closed to new replies.

About this Topic