Filter Search through multiple Custom Post Types (1 post)

  1. Cirkut
    Posted 4 years ago #

    I'm working on a theme right now, and have added three custom post types: [Jobs, Opportunities, Resources].

    On every page (along with my nav) I have a search field along with three checkboxes, each labeled respectively with their custom post type.

    I originally had the theme using three categories (named the same as above), and was able to figure out how to filter the search (albeit with a rather long if statement checking if each of the checkboxes were selected). However, I need to add custom meta boxes to each of the three custom post types (which is why I changed them from categories). I figured this out with relative ease, but now I'm having a difficult time trying to figure out how to query and filter the search based on which checkboxes are selected. Here is my current search code:


    If you notice this section here:

    <?php $job = wp_specialchars(stripslashes($_GET["job"]), 1);?>
    	<?php $opportunity = wp_specialchars(stripslashes($_GET["opportunity"]), 1);?>
    	<?php $resource = wp_specialchars(stripslashes($_GET["resource"]), 1);?>
    	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	$cat = (get_query_var('cat')) ? get_query_var('cat') : 0;
    	$searchtag = (get_query_var('tag')) ? get_query_var('tag') : '';
    	if($job == '1' && $opportunity == '1' && $resource == '1'){
    		$cat = '4,5,6';
    	}elseif($job == '1' && $opportunity == '1'){
    		$cat = '4,5';
    	}elseif($job == '1' && $resource == '1'){
    		$cat = '4,6';
    	}elseif($opportunity == '1' && $resource == '1'){
    		$cat = '5,6';
    	}elseif($job == '1'){
    		$cat = '4';
    	}elseif($opportunity == '1'){
    		$cat = '5';
    	}elseif($resource == '1'){
    		$cat = '6';

    The above is my if statement for checking each checkboxes and applying categories to the query. However creating an array of custom post types I'm sure is different. And I've tried changing the last statement to $ptype = 'resources'; to see if it would filter at all, but alas, it does not. If you need any more information that could help me, I'll be more than happy to provide it.

    One last thing, here's the link to the site that I'm working on: http://www.cirkut.net/wp/libertyguide

Topic Closed

This topic has been closed to new replies.

About this Topic