Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

WP Custom Post Type Search

Posted on 2014-01-28
2
Medium Priority
?
506 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 2000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

688 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