Im successfully filtering ALL my Wordpress posts by Likes (count) with a Custom Plugin (and meta_key) wich also let me filter the most liked posts in categories. I display (query) the result in a custom page template. Everything works fine.
The Like function works also on Woocommerce Products. But so far i was not able to set up a page where i sort the Products (post_type) the same way in a specific shop cateogry as i do it with my posts. The closest i came was to display the most liked posts on the page BUT the sorting for a category does not filter the posts - it displays the same as in the main page. The category List and the url call for the cateogy links are working fine.
NOTE: THE url query-string "product-cato" is a custom one - im using a ajax filter plugin wich uses this query-string and the category id like .../?product-cato=6
Please do not mix it up wicht product_cat
for example
This is what i came up so far - beginning with the code for the posts (wich works fine). Any idea how to solve this issue? thx
The query (works fine)
if (isset($_GET['category'])) {
$args = array(
'meta_key' => '_recoed',
'meta_compare' => '>',
'meta_value' => '0',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'category_name' => sanitize_text_field($_GET['category']),
'paged' => $paged
);
}
query_posts($args);
The Category List to Filter the Post in each Category (works fine)
<?php $categories = get_categories();
foreach($categories as $category) { ?>
<li>
<a class="popular-categories" href="<?php echo get_permalink(); ?>?category=<?php echo $category->category_nicename; ?>"><?php echo $category->name; ?></a>
</li>
<?php } ?>
Now the Woocommerce Query and Category Part where I am stucks
The Query for the Products post_type
if (isset($_GET['product-cato'])) {
$args = array(
'meta_key' => '_recoed',
'meta_compare' => '>',
'meta_value' => '0',
'post_type' => 'product',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'taxonomy' => sanitize_text_field($_GET['product_cat']),
'paged' => $paged
);
query_posts($args);
The Category List to Filter the Post in each Shop-Category
<?php
$product_categories = get_terms( 'product_cat' );
$count = count($product_categories);
foreach ( $product_categories as $product_category ) { ?>
<li>
<a class="popular-categories" href="<?php echo get_permalink(); ?>?product-cato=<?php echo $product_category->term_id; ?>"><?php echo $product_category->name; ?></a>
</li>
}
?>