In WooCommerce, I want to implement a custom product sorting option based on a database custom table column named "click_count". This custom sorting works perfectly on the shop page, but doesn't work with my product category or product tag archive pages. Note that I’m using custom permalinks for those categories and tags: Product category: https://posterartshop.de/poster-kategorie/ Product tag: https://posterartshop.de/poster-schlagwort/ The default sorting options (by price, name, etc.) work fine on these pages, but the custom sorting does not. Here is the relevant code I've added to my theme functions.php file: // Add custom sorting for popular products function custom_join_for_product_clicks($clauses, $wp_query) { global $wpdb; // Check if it's a product query and the 'clicks_desc' sorting is selected if ( (is_shop() || is_product_taxonomy() || is_tax('poster-category') || is_tax('poster-tag')) && isset($wp_query->query_vars['orderby']) && 'clicks_desc' == $wp_query->query_vars['orderby'] ) { // Join the clicks table $clauses['join'] .= " LEFT JOIN {$wpdb->prefix}product_clicks ON {$wpdb->prefix}posts.ID = {$wpdb->prefix}product_clicks.product_id"; $clauses['orderby'] = " {$wpdb->prefix}product_clicks.click_count DESC"; } return $clauses; } add_filter('posts_clauses', 'custom_join_for_product_clicks', 10, 2); // Add custom sort option function add_custom_sort_option($options) { $options['clicks_desc'] = __('Popular Products', 'textdomain'); // Text changed here return $options; } add_filter('woocommerce_get_catalog_ordering_args', 'add_custom_sort_option'); add_filter('woocommerce_default_catalog_orderby_options', 'add_custom_sort_option'); add_filter('woocommerce_catalog_orderby', 'add_custom_sort_option'); What could be causing this issue? How can I ensure that the custom sorting is applied correctly on all product listing pages, including product category and tag archive pages?