Custom Data / Product / Card Filter by page load (by get and isset function)
Tue Sep 12 2023 07:50:49 GMT+0000 (Coordinated Universal Time)
Saved by
@gshailesh27
//List All Texonomy
<?php
// Get the taxonomy's terms
$terms = get_terms(
array(
'taxonomy' => 'product_category',
'hide_empty' => true,
)
);
// Check if any term exists
if ( ! empty( $terms ) && is_array( $terms ) ) {
// Run a loop and print them all
foreach ( $terms as $term ) {
$class99='';
if($_GET['cat']==$term->slug) $class99='active';
?>
<div>
<a href="<?php echo site_url(); ?>/products/?cat=<?php echo esc_attr( $term->slug ); ?>" class="productName js-filter" data-color="<?php echo $term->slug; ?>"><?php echo $term->name; ?></a>
</div>
<?php
}
}
?>
//Data Filter Query and then add white loop
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
//$taxo='';
$category99='';
if(isset($_GET['cat']))
{
$category99=$_GET['cat'];
//$taxo=$_GET['taxo'];
$args = array(
'post_type' => 'products',
'paged' => $paged,
'post_status' => 'publish',
'posts_per_page' => 12,
'orderby' => 'title',
'product_category' => $category99,
//'resourceservicetexo' => $taxo,
'order' => 'ASC',
'post__not_in' => array(get_the_ID()),
);
}
else
{
$args = array(
'post_type' => 'products',
'paged' => $paged,
'post_status' => 'publish',
'posts_per_page' => 12,
'orderby' => 'title',
'order' => 'ASC',
'post__not_in' => array(get_the_ID()),
);
}
content_copyCOPY
Comments