WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Identify Post Type Filter on Search Results Page (2 posts)

  1. Mav3000
    Member
    Posted 2 years ago #

    Hi, I have a site with two Post Types, each have their own search boxes which filter search results to a specific post type.

    On my search.php page, I'd like to be able to extract which Post Type my results are filtered to.

    How can I do this?

    The URL of my search results looks like this:

    http://www.domain.com/?s=mysearchtext&post_type=mypostype

    Any help would be really appreciated.

  2. Mav3000
    Member
    Posted 2 years ago #

    I've solved this one myself by searching for similar answers.

    I came across this thread:

    http://wordpress.org/support/topic/problems-with-is_post_type-perhaps-it-is-a-bug?replies=25

    Where the answer lies in:

    <?php
    	$post_type = get_post_type( $post );
    	if ( $post_type == 'posttype1' ) { ?>
    	<p>The Post Type is Type 1!</p>
    <?php } else if ( $post_type == 'posttype2' ) { ?>
    	<p>The Post Type is Type 2!</p>
    <?php } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic