adding filtering by attributes to products
-
Hello
thanks for the support and great plugin!
Please tell me – I have a code and it works fine for filtering in the Product by the pa_brand attribute. (code below)add_action( 'restrict_manage_posts', 'aws_brand_products_sorting' ); function aws_brand_products_sorting() { global $typenow; $post_type = 'product'; // change to your post type $taxonomy = 'pa_brand'; // change to your taxonomy if ($typenow == $post_type) { $selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : ''; $info_taxonomy = get_taxonomy($taxonomy); //$selected = isset($_GET[$info_taxonomy->name]) ? $_GET[$info_taxonomy->name] : ''; wp_dropdown_categories(array( 'show_option_all' => __("Brand {$info_taxonomy->label}", "aws-multi-functions"), 'taxonomy' => $taxonomy, 'name' => $taxonomy, 'orderby' => 'name', 'selected' => $selected, 'show_count' => true, 'hide_empty' => true, )); }; } add_filter( 'parse_query', 'aws_brand_products_sorting_query' ); function aws_brand_products_sorting_query( $query ) { global $pagenow; $post_type = 'product'; // change to your post type $taxonomy = 'pa_brand'; // change to your taxonomy $q_vars = &$query->query_vars; if ( $pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && isset($q_vars[$taxonomy]) && is_numeric($q_vars[$taxonomy]) && $q_vars[$taxonomy] != 0 ) { $term = get_term_by('id', $q_vars[$taxonomy], $taxonomy); $q_vars[$taxonomy] = $term->slug; } }
But I need to add more filtering on the pa_seller attribute.
I am changing the name of the attribute – please see the code below. – but it doesn’t work.add_action( 'restrict_manage_posts', 'aws_seller_products_sorting' ); function aws_seller_products_sorting() { global $typenow; $post_type = 'product'; // change to your post type $taxonomy = 'pa_seller'; // change to your taxonomy if ($typenow == $post_type) { $selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : ''; $info_taxonomy = get_taxonomy($taxonomy); //$selected = isset($_GET[$info_taxonomy->name]) ? $_GET[$info_taxonomy->name] : ''; wp_dropdown_categories(array( 'show_option_all' => __("Seller {$info_taxonomy->label}", "aws-multi-functions"), 'taxonomy' => $taxonomy, 'name' => $taxonomy, 'orderby' => 'name', 'selected' => $selected, 'show_count' => true, 'hide_empty' => true, )); }; } add_filter( 'parse_query', 'aws_seller_products_sorting_query' ); function aws_seller_products_sorting_query( $query ) { global $pagenow; $post_type = 'product'; // change to your post type $taxonomy = 'pa_seller'; // change to your taxonomy $q_vars = &$query->query_vars; if ( $pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && isset($q_vars[$taxonomy]) && is_numeric($q_vars[$taxonomy]) && $q_vars[$taxonomy] != 0 ) { $term = get_term_by('id', $q_vars[$taxonomy], $taxonomy); $q_vars[$taxonomy] = $term->slug; } }
Please help, what am I doing wrong with the second code and pa_seller attributes?
Why is the second code not filtering? (the filtering and selection box appears, but the filtering itself does not occur).Thanks a lot for your help
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘adding filtering by attributes to products’ is closed to new replies.