• Home
  • About Mitch
  • Speaking
  • Articles
  • Contact
  • Home
  • About Mitch
  • Speaking
  • Articles
  • Contact

Digital Strategist

WordPress Developer

Content Creator

Unapologetic Punk

Mitch Canter

  • X
  • Bluesky
  • GitHub
  • Twitch
  • YouTube
  • LinkedIn
Development

How To Search A Specific Custom Post Type (Only!) in WordPress

CMDR Mitchcraft

Reading time: 1 minute

If you’re like me, you use custom post types a LOT when you’re doing projects (or on your own site, if I’ve done it for you!).  There’s a lot of value in having a type of content that’s unrestrained and flexible.  Sometimes, however, you want to be able to search a particular post type, and leave out all of the other results (pages, blog posts, etc).  Here’s a handy snippet that will let you do just that (for example, a ‘products’ post type):

<form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
<input type="text" placeholder="Search" name="s" id="s" />
<input type="hidden" name="post_type" value="products" />
<input type="hidden" id="searchsubmit" />
</form>

Line 3 is the key – it’s a hidden field that defines the “post_type” as whatever value you have there (the query variable, not the name mind you).

As an added bonus, this particular search button clears the default text on click so as not to have an awkward empty search box when you first access it.

Add this into any template and you’ve got yourself a laser-specific search box for your custom post needs.

code snippit, custom post type, search, WordPress
  • Foursquare vs. Gowalla… annnnnd fight!

    Foursquare vs. Gowalla… annnnnd fight!

    Reading time: 5 minutes

    <script type=”text/javascript”>function initMenus() {    $(‘ul#accordion li ul’).hide();    $.each($(‘ul#accordion’), function(){        $(‘#’ + this.id + ‘.expandfirst ul:first’).show();    });    $(‘ul#accordion li h2.widgettitle’).click(        function() {            var checkElement = $(this).next();            var parent = this.parentNode.parentNode.id;             if($(‘#’ + parent).hasClass(‘noaccordion’)) {                $(this).next().slideToggle(‘normal’);                return false;            }            if((checkElement.is(‘ul’)) && (checkElement.is(‘:visible’))) {                if($(‘#’ + parent).hasClass(‘collapsible’)) {                    $(‘#’ + parent + ‘ ul:visible’).slideUp(‘normal’);                }                return false;           …

    Tutorial, WordPress
  • WordPress BootCamp: Categories vs Tags

    WordPress BootCamp: Categories vs Tags

    Reading time: 2 minutes

    This is the second post of Mitch Canter’s “WordPress BootCamp” series… it showcases the ins and outs of WordPress to new users, and highlights some of the more popular (and some overlooked) features that make WordPress fantastic.  You can catch all of the posts here. I get a lot of questions on this: “What’s the…

    WordPress