Solved

WP Custom Post Type Search

Posted on 2014-01-28
2
482 Views
Last Modified: 2014-01-29
I am using a custom search form on my site that will only show results from one of my custom post types (CPT). I've done this basically by adding a hidden input field like this:

<form id="searchform" action="<?php bloginfo('url'); ?>/" method="get"> 
   <input class="inlineSearch" type="text" name="s" value="Search"  /> 
   <input type="hidden" name="post_type" value="my_post_type" /> 
   <input id="searchsubmit" type="submit" value="Search" /> 
</form>

Open in new window

When a user submits this form, it takes them to the default 'search.php' page to show the results (I have another search form on my site that uses the same page). However, I want a few things to either not appear or display differently if a user gets to my search page after using the CPT form. I know that I can create a custom search page to show the results of my CPT search but it may be a bit of overkill as I pretty much want the same page as search.php with just a few minor alterations.

So I guess my question is, is it possible to use some sort of "if" statement to identify if the search is specifically from my custom post type search and show/hide something in search.php as a result? Hope that makes sense. Any help would be much appreciated. Thanks!
0
Comment
Question by:Adam
2 Comments
 
LVL 14

Accepted Solution

by:
Dzynit earned 500 total points
ID: 39818367
You can check for your hidden field with the if statement.

if ($_REQUEST('post_type) == 'my_post_type') {
// do this
}

or change the == to != if you only want that piece of code to show if it's not on that custom post type.
0
 
LVL 1

Author Closing Comment

by:Adam
ID: 39819809
Perfect. Just what I needed. Thanks!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question