Last active
December 15, 2015 09:19
-
-
Save flyarrowplane/5237317 to your computer and use it in GitHub Desktop.
The snippet below shows how the $args are gathered for an advanced search. The Instrument and Doctype items are checkboxes -- meaning that if multiple items of each are checked, the request object returns a comma-delimited list of IDs. The issue is that whatever I put into $args['category__and'] (and I've tried here just using $args['cat'], too)…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Check if results should be filtered | |
$search_filter = $_REQUEST["search_filter"]; | |
$search_keyword = $_REQUEST["search_keyword"]; | |
$search_instrument = $_REQUEST["search_instrument"]; | |
$search_doctype = $_REQUEST["search_doctype"]; | |
echo "<br />search_filter: " . $search_filter; | |
echo "<br />search_keyword: " . $search_keyword; | |
echo "<br />search_instrument: " . $search_instrument; | |
echo "<br />search_doctype: " . $search_doctype ; | |
echo "<br /><br />"; | |
// ............ more stuff here | |
// if the search filter is used | |
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; | |
$args = array( | |
'post_status' => 'publish', | |
'posts_per_page' => 20, | |
'paged' => $paged, | |
'order' => 'ASC', | |
'meta_key' => 'support-file-url', | |
'orderby' => 'meta_value, post_title' | |
); | |
// add on custom query info | |
if($search_instrument != "" && $search_doctype != "") | |
{ | |
// for testing | |
print_r ($search_instrument); | |
print_r ($search_doctype); | |
$merged_arrays = array_merge($search_instrument, $search_doctype); | |
print_r ($merged_arrays); | |
$args['category__and'] = array_merge($search_instrument, $search_doctype); | |
} | |
else if($search_instrument != "" && $search_doctype == "") | |
{ | |
$args['category__and'] = $search_instrument; | |
} | |
else if($search_instrument == "" && $search_doctype != "") | |
{ | |
$args['category__and'] = $search_doctype; | |
} | |
else if($search_instrument == "" && $search_doctype == "") | |
{ | |
$docttype_cats = get_categories("child_of=137"); // if no category selected, get all posts associated with the document categories | |
$cat_list = ""; | |
foreach ($docttype_cats as $category) { | |
$cat_list .= $category->cat_ID . ","; | |
} | |
$cat_list = substr($cat_list,0,strlen($cat_list)-1); | |
$args['cat'] = $cat_list; | |
} | |
// add on keyword | |
if($search_keyword != "") | |
{ | |
$args['s'] = $search_keyword; | |
} | |
// output filter details if testing enabled | |
if($_REQUEST["test"] == "yes") | |
{ | |
foreach ($args as $key => $value) | |
{ | |
echo "<br />" . $key . ": " . $value; | |
foreach ($value as $key2 => $value2) | |
{ | |
echo "<br />--" . $key2 . ": " . $value2; | |
} | |
} | |
echo "<br /><br />" . $GLOBALS['wp_query']->request; | |
} | |
query_posts( $args ); | |
// ............ more stuff here, display, etc. | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment