• Resolved abdessamed

    (@abdessamed)


    Hello there
    I have installed Annasta Filters and it work perfectly on shop page, but when i make a custom query to this page to show products by Tags, the plugin wont work,
    this is the code that i’m using

    
    <?php
    $args = array(
                    'number'     => $number,
                    'orderby'    => 'title',
                    'order'      => 'ASC',
                    'hide_empty' => $hide_empty,
                    'include'    => $ids
                );
                $product_tags = get_terms( 'product_tag', $args );
                $count = count($product_tags);
                if ( $count > 0 ){
                    foreach ( $product_tags as $product_tag ) {
                        echo '<h4>' . $product_tag->name . '</a></h4>';
                        $args = array(
                            'posts_per_page' => -1,
                            'tax_query' => array(
                                'relation' => 'AND',
                                array(
                                    'taxonomy' => 'product_tag',
                                    'field' => 'slug',
                                    // 'terms' => 'white-wines'
                                    'terms' => $product_tag->slug,
                                    'product_tag'=> "latest-product"
                                )
                            ),
                            'post_type' => 'product',
                            'orderby' => 'title,'
                        );
                        $products = new WP_Query( $args );
                        woocommerce_product_loop_start();
                        while ( $products->have_posts() ) {
                            $products->the_post();
                            do_action( 'woocommerce_shop_loop' );
                            wc_get_template_part( 'content', 'product' );
                            ?>
                                
                            <?php
                        }
                        woocommerce_product_loop_end();
                    }
                }
             ?>
    

    and this is the display

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author annastaa

    (@annastaa)

    Hello abdessamed,

    The custom query doesn’t work because our filters support only the native Woocommerce shop loop, archive pages, or the Woocommerce “products” shortcode.

    The simplest way to filter by tag is to use the archive pages. They are natively supported by the Woocommerce, and are usually available at http://www.yoursite.com/product-tag/the-needed-tag. Click here to see an example of such page from our demo site.

    Another way would be to make use of the Woocommerce “products” shortcode. You can set up as many tag pages as you need with the help of the “tag” attribute of the shortcode.

    Hope this helps!

    Thread Starter abdessamed

    (@abdessamed)

    Thank you very much
    it work with shortcode
    this is the code that i’m using now

     <?php 
                $args = array(
                    'number'     => $number,
                    'orderby'    => 'title',
                    'order'      => 'ASC',
                    'hide_empty' => $hide_empty,
                    'include'    => $ids
                );
                $product_tags = get_terms( 'product_tag', $args );
                $count = count($product_tags);
                if ( $count > 0 ){
                    foreach ( $product_tags as $product_tag ) {
                        if ($product_tag->count>0){
                            echo '<h3 class="tagname">' . $product_tag->name . '</a></h4>';
                            echo do_shortcode( '[products tag="'.$product_tag->slug.'"]' );
                        }
                        
                     
                    }
                }
             ?>
                <?php 
    • This reply was modified 5 years, 4 months ago by abdessamed.
    Plugin Author annastaa

    (@annastaa)

    abdessamed,

    I am glad to hear that you found a suitable solution, thank you for sharing it with other users of our support forum!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Plugin wont Filter custom shop page’ is closed to new replies.