Sziasztok!
Tegnap szembesültem azzal hogy valamiért egy kategóriánál a count érték nem megfelelő … picit számolgatás után rájöttem hogy az alkategória elemeit is bele számolja…
nem tudtam eldönteni hogy ez most normális mükődésnek számít de nekem nem volt logikus…
pl (admin->products>categories):
kategóriák:
- a (10db - ténylegesen 2db product van benne)
- b (6db)
- c (2db)
.
.
.
igen kerek szemekkel néztem mi is van itt … egy kis keresgélés után láttam hogy a wp bevezetett egy tax_query változott => include_children … végül a megoldásom admin felületre:
if (is_admin()) {
add_filter(“request”, “hydro_products_filter_by_taxonomy_bugfix”);
function hydro_products_filter_by_taxonomy_bugfix($query)
{
global $pagenow;
if ($pagenow == “edit.php” && $query[‘post_type’] == “product” && isset($query[‘product_cat’])) {
if (!$query[‘tax_query’]) {
$query[‘tax_query’] = array();
}
$query[‘tax_query’][‘relation’] = “AND”;
$tmp_query = array();
$tmp_query[‘taxonomy’] = “product_cat”;
$tmp_query[‘field’] = “slug”;
$tmp_query[‘terms’] = $query[‘product_cat’];
$tmp_query[‘operator’] = “IN”;
$tmp_query[‘include_children’] = FALSE;
$query[‘tax_query’][] = $tmp_query;
}
return $query;
}
add_filter(“get_terms_args”,“hydro_products_filter_select_count_bugfix”,10,2);
function hydro_products_filter_select_count_bugfix($args,$taxonomies)
{
$found = false;
foreach($taxonomies as $tax)
{
if($tax === “product_cat”)
{
$found = true;
}
}
if($found === true)
{
$args[‘pad_counts’] = 0;
}
return $args;
}
}
ezek után már jól fogja kezelni…
pl (admin->products>categories):
kategóriák:
- a (2db)
- b (6db)
- c (2db)
if (is_admin()) {
add_filter(“request”, “hydro_products_filter_by_taxonomy_bugfix”);
function hydro_products_filter_by_taxonomy_bugfix($query)
{
global $pagenow;
if ($pagenow == “edit.php” && $query[‘post_type’] == “product” && isset($query[‘product_cat’])) {
if (!$query[‘tax_query’]) {
$query[‘tax_query’] = array();
}
$query[‘tax_query’][‘relation’] = “AND”;
$tmp_query = array();
$tmp_query[‘taxonomy’] = “product_cat”;
$tmp_query[‘field’] = “slug”;
$tmp_query[‘terms’] = $query[‘product_cat’];
$tmp_query[‘operator’] = “IN”;
$tmp_query[‘include_children’] = FALSE;
$query[‘tax_query’][] = $tmp_query;
}
return $query;
}
add_filter(“get_terms_args”,“hydro_products_filter_select_count_bugfix”,10,2);
function hydro_products_filter_select_count_bugfix($args,$taxonomies)
{
$found = false;
foreach($taxonomies as $tax)
{
if($tax === “product_cat”)
{
$found = true;
}
}
if($found === true)
{
$args[‘pad_counts’] = 0;
}
return $args;
}
}
ezek után már jól fogja kezelni…
pl (admin->products>categories):
kategóriák:
- a (2db)
- b (6db)
- c (2db)