admin管理员组文章数量:1425772
I have written code that filters products by manufacturer. On one website this code works on second not working ... can you help me with this? After filtorvani products website take one product even though the manufacturer has 158 products.
function filter_by_manufacture() {
$params = array(
'name' => 'vyrobca',
'show_option_all' => 'Vyberte výrobcu',
'taxonomy' => 'vyrobca',
'show_count' => 1,
'value_field' => 'slug'
);
if ( isset($_GET['vyrobca']) )
$params['selected'] = $_GET['vyrobca'];
if ( get_post_type() == 'product' ) {
wp_dropdown_categories( $params );
}
}
add_action('restrict_manage_posts', 'filter_by_manufacture');
I don't understand why the code shouldn't work
I have written code that filters products by manufacturer. On one website this code works on second not working ... can you help me with this? After filtorvani products website take one product even though the manufacturer has 158 products.
function filter_by_manufacture() {
$params = array(
'name' => 'vyrobca',
'show_option_all' => 'Vyberte výrobcu',
'taxonomy' => 'vyrobca',
'show_count' => 1,
'value_field' => 'slug'
);
if ( isset($_GET['vyrobca']) )
$params['selected'] = $_GET['vyrobca'];
if ( get_post_type() == 'product' ) {
wp_dropdown_categories( $params );
}
}
add_action('restrict_manage_posts', 'filter_by_manufacture');
I don't understand why the code shouldn't work
Share Improve this question edited May 31, 2019 at 12:53 LoicTheAztec 3,39117 silver badges24 bronze badges asked May 31, 2019 at 5:32 uhercikuhercik 132 silver badges5 bronze badges 2- this problem make plugin "WooCommerce Search by Product SKU" sk.wordpress/plugins/woo-search-by-product-sku – uhercik Commented May 31, 2019 at 6:28
- Any chance to get some feed back on the answer please, Thank you. – LoicTheAztec Commented Aug 7, 2019 at 1:00
1 Answer
Reset to default 1There is some missing parts in your code:
Try the following:
add_action('restrict_manage_posts', 'admin_products_by_manufacturer_filter_dropdown');
function admin_products_by_manufacturer_filter_dropdown() {
global $typenow, $pagenow;
$taxonomy = 'vyrobca'; // The custom taxonomy
if( 'edit.php' === $pagenow && 'product' === $typenow && taxonomy_exists( $taxonomy ) ) {
$info_taxonomy = get_taxonomy($taxonomy);
$selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
wp_dropdown_categories( array(
'show_option_all' => sprintf( __("Zobraziť všetkých %s", "woocommerce"), $info_taxonomy->label ),
'taxonomy' => $taxonomy,
'name' => $taxonomy,
'selected' => $selected,
'orderby' => 'name',
'show_count' => true,
'hide_empty' => true,
) );
}
}
add_action('parse_query', 'admin_products_by_manufacturer_filter_query');
function admin_products_by_manufacturer_filter_query( $query ) {
global $typenow, $pagenow;
$taxonomy = 'vyrobca'; // The custom taxonomy
if ( 'edit.php' === $pagenow && 'product' === $typenow && taxonomy_exists( $taxonomy ) ) {
$q_vars = &$query->query_vars;
if ( 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;
}
}
}
Code goes in functions.php file of your active child theme (or active theme). It should works.
本文标签: Filter WooCommerce admin products list by a custom taxonomy
版权声明:本文标题:Filter WooCommerce admin products list by a custom taxonomy 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745448155a2658758.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论