Last active
September 20, 2021 15:35
-
-
Save Quin452/6e4fcae4b2506f629362c9423e8d33f4 to your computer and use it in GitHub Desktop.
This file contains 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
// What were searching for | |
$args = array( | |
'post_type' => $post_type, | |
'post_status' => 'publish' | |
); | |
// Now, if the category has been selected AND it doesn't equal the "show all" value | |
if(isset($_POST['category']) && $_POST['category'] != -1) { | |
// Explode the string into an array | |
$categories = array_map('intval', explode(',', $_POST['category'])); | |
// Then load the POST array into the cat args | |
$args['category__in'] = $categories; | |
} | |
// Yep, a query | |
$query = new WP_Query($args); | |
// Loop through | |
if($query->have_posts()) { | |
// Do your thing here | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@User0123456789 do you have a link to your site I can look at?