Forums

[resolved] Search page loop: how to test if result is a page? (6 posts)

  1. jared123
    Member
    Posted 11 months ago #

    In my search results page on my theme, the category of each post that is turned up by the search is displayed. this is fine. the problem is, if the search finds a match in a Page, then it shows the Page as being posted in "uncategorized" even though pages don't have categories.

    i am trying to figure out a way to test if the current post is a page within the search results loop and not print the category if it is a page.

    how would i go about that?

  2. MichaelH
    moderator
    Posted 11 months ago #

    I'd guess the Conditional Tag, is_page() would work.

  3. jared123
    Member
    Posted 11 months ago #

    MichaelH - thanks, but I tried that already and it doesn't work. i think it's because is_page() tests for what sort of page you're on, and in a search results page, this always returns false.

  4. MichaelH
    moderator
    Posted 11 months ago #

    Then in a post loop what about testing for 'page' == $post->post_type

  5. jared123
    Member
    Posted 11 months ago #

    brilliant! that did it, many thanks!

  6. wrk
    Member
    Posted 10 months ago #

    SUPER! worked also for me, live can be as easy as this:D

    THANKS!

Reply

You must log in to post.

About this Topic