Custom Filter
-
Hello
I have made a custom HTML and used it using shortcode and it contains products from a specific category, so how can I apply your filters in it my custom html shortcode?
Example:
function display_sample_category_products(){ ?>
<div class="product-list-inner">
<?php
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => 12,
'order' => 'DESC',
'paged' => 1,
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => 171,
'operator' => 'IN'
),
)
);
$query = new WP_Query($args);
if ($query->have_posts()) :
?>
<div class="product-list flex no-wrap direction-column load-sample-list">
<?php
while ($query->have_posts()) : $query->the_post();
global $product;
$product_id = get_the_ID();
$_product = wc_get_product( $product_id );
$url = wp_get_attachment_url( get_post_thumbnail_id($product_id), 'full' );
?>
<div class="product-select-items">
<div class="product-select">
<div class="product-select-inner flex align-center position-relative">
<div class="product-img">
<a class="aspect-ratio" href="<?php the_permalink(); ?>">
<img src="<?php echo $url; ?>" alt="<?php the_title(); ?>">
</a>
</div>
<div class="product-content flex-1 grid grid-col-2">
<div class="content">
<div class="title">
<a href="<?php the_permalink(); ?>">
<h2 class="woocommerce-loop-product__title"><?php the_title(); ?></h2>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
endwhile;
wp_reset_postdata(); ?>
</div>
<?php
$numposts = $query->post_count;
if($numposts > 5){
?>
<div class="product-list-load load-more-wrap">
<a href="javascript:void(0);" class="btn ct-white load-more-sample-product">Load More</a>
</div>
<?php } ?>
<?php else: ?>
<p class="body1"><?php _e( 'Sorry, no product matched your criteria.' ); ?></p>
<?php endif; ?>
</div>
<?php
}
add_shortcode('sample_category_products', 'cs_display_sample_category_products');[sample_category_products]
In this case how may i apply your filter in my sort code with use load more button?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Custom Filter’ is closed to new replies.