-1 SQL error?" />
G
G
GeKskill2021-08-25 00:36:29
WordPress
GeKskill, 2021-08-25 00:36:29

'posts_per_page" => -1 SQL error?

I want to make a copy of the main query but without a limit, in such an implementation an SQL error comes out (adds -1 to the query).
What is the best way to do this?

//* Фильтр по тегам категории
function get_tags_based_on_cat($products){

  $all_tags = $tag_ids = array();
    foreach ($products as $product) {
        $tag_ids = array_merge($tag_ids, $product->get_tag_ids());
    }

$tag_ids = array_unique($tag_ids);

    foreach ($tag_ids as $key => $tag_id) {
        $tag_obj = get_term_by('id', $tag_id, 'product_tag');
        $all_tags[] = array( 'term_id' => $tag_obj->term_id, 'name' => $tag_obj->name, 'slug' => $tag_obj->slug );
    }

  return $all_tags;
}
add_action( 'woocommerce_before_shop_loop', function(){

        if ( !is_product_category()) {
            return;
        };

        global $wp_query;
        $before = microtime(true);
        $query_vars = array_merge($wp_query->query_vars, array('posts_per_page'  =>  -1)) ;
        $products = wc_get_products( $query_vars );
        $cat_tags = get_tags_based_on_cat($products);
        wc_get_template('loop/hashtags-cloud.php', array( 'tags' => $cat_tags ));
        echo console_log(number_format(( microtime(true) - $before), 4));
});


P / s entered posts_per_page => 999 - this works, but it should also digest -1

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