Solved

WP Custom Post Type Search

Posted on 2014-01-28
2
477 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now