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 | |
} |
@User0123456789 do you have a link to your site I can look at?
@Quin452 it's still in my local env. But I can post the js code here. Wait a moment
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Quin452 I tried to change the
<select name="categories">
to<select name="category">
but all the posts in other options are not displayed. Do you mean if statement in html/php file?I used
cat_args
hereand for the category 1 and 2, and I use it to show different categories depends in the page slug name.