T
T
twentytvvo2021-01-25 16:22:34
WordPress
twentytvvo, 2021-01-25 16:22:34

How to fix php output of products through Wp_Query?

I used the Themify plugin to filter products by attributes and price range, edited its cycles and fields for myself, in fact changed the plugin for myself.

It filters well through ajax cycles of products that are called through a shortcode, but shortcodes do not suit me, because I have no idea how to use hooks and I'm just looking for a way to display a cycle in php where I can put any class on each block. I found the WP_QUERY output for myself, it suits me from the visual part, but there is one "but". The block with the WP_QUERY loop does not react in any way to filtering through this plugin . Or rather, even to say that there is an imitation of activity, but there is no filtering as such.

First of all, I thought that the correct attributes were not specified in array.

<?php

$loop = new WP_Query( array(
'post_type' => 'product',
'posts_per_page' => '12',
));

while ( $loop->have_posts() ): $loop->the_post(); ?>

<div <?php post_class("catalog-block"); ?>>
<a href="" class="image"><?php the_post_thumbnail("thumbnail-215x300"); ?></a>
<div class="name"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
<?php woocommerce_template_loop_price(); ?>
<?php woocommerce_template_loop_add_to_cart(); ?>
</div>

<?php endwhile; wp_reset_postdata(); ?>

Here is the loop code by the way. Right now it's just the number of products per page and the post type.
I tried to catch attributes from the URL, but the hands are crooked and none of this worked.
I was looking for some clues in the php plugin, I can set it with the same attributes, maybe it will work, but I can’t find the right ones.
Link to php filtering form https://dropmefiles.com/13qSE .
And among other things, there is no sorting option in the form by price, default, etc. Therefore, I thus deduced the same sorting:
<?php
    $catalog_orderby = apply_filters( 'woocommerce_catalog_orderby', array(
     'menu_order' => __( 'Default sorting', 'woocommerce' ),

    'price'      => __( 'Sort by price: low to high', 'woocommerce' ),

    'price-desc' => __( 'Sort by price: high to low', 'woocommerce' )
) );

if ( get_option( 'woocommerce_enable_review_rating' ) == 'no' )
    unset( $catalog_orderby['rating'] );

foreach ( $catalog_orderby as $id => $name )
    echo '<li>
<span class="filter-checkbox sort-hover">
<a href="' . get_permalink( woocommerce_get_page_id( 'shop' ) ) . '?orderby=' . $id . '" >' . esc_attr( $name ) . '</a>
</span>
</li>';
?>

What does it mean that it is necessary for the cycle code to catch from the url "orderby".

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question