Created
February 13, 2023 07:16
-
-
Save crispyabsurdist/ce824e7915658bd5c70ccbc7c30daff1 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
<?php | |
public function postFilter() | |
{ | |
// Define custom post type and taxonomies | |
$post_type = 'product'; | |
$taxonomies = array('brand', 'category'); | |
// Get the current page number | |
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; | |
// Define the query arguments | |
$args = array( | |
'post_type' => $post_type, | |
'posts_per_page' => 10, | |
'paged' => $paged, | |
'tax_query' => array() | |
); | |
// Get the taxonomy terms from the URL | |
foreach ($taxonomies as $taxonomy) { | |
if (isset($_GET[$taxonomy]) && !empty($_GET[$taxonomy])) { | |
$args['tax_query'][] = array( | |
'taxonomy' => $taxonomy, | |
'field' => 'slug', | |
'terms' => $_GET[$taxonomy] | |
); | |
} | |
} | |
// Run the query | |
$query = new WP_Query($args); | |
// Check if there are any posts | |
if ($query->have_posts()) { | |
while ($query->have_posts()) { | |
$query->the_post(); | |
// Display the post | |
} | |
// Pagenation | |
$big = 999999999; // need an unlikely integer | |
} else { | |
// No Posts Found | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment