Solved

WP Custom Post Type Search

Posted on 2014-01-28
2
487 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

732 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