Solved

WP Custom Post Type Search

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

Database Solutions Engineer FAQs

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller single-server environments.

Question has a verified solution.

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

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…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

627 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