Answer the question
In order to leave comments, you need to log in
How to find the Misc category in an array in WordPress?
Actually, I've been trying to find the non-removable Misc category in the array all day, since I need to hide it. I will sign, everything in stages: I
brought out a list of all categories with a hook:
function get_categories_product($categories_list = "", $parent_id = 0, $inumberPlus = 0) {
$get_categories_product = get_terms("product_cat", [
"orderby" => "name", // Тип сортировки
"order" => "ASC", // Направление сортировки
"hide_empty" => 0, // Скрывать пустые. 1 - да, 0 - нет.
"hierarchical" => 1,
"parent" => $parent_id
]);
if(count($get_categories_product) > 0) {
if($parent_id == 0) {
$categories_list .= '<ul class="main_categories_list">';
$inumberPlus = 0;
} else {
$inumberPlus++;
$categories_list .= '<ul class="sub_categories_list sub_categories_list_'.$inumberPlus.'">';
}
foreach($get_categories_product as $categories_item) {
$categories_list .= '<li><a href="'.esc_url(get_term_link((int)$categories_item->term_id)).'">'.esc_html($categories_item->name).'</a>';
$categories_list .= get_categories_product("", $categories_item->term_id, $i);
$categories_list .= '</li>';
}
$categories_list .= '</ul>';
}
return $categories_list;
}
<?php
$getMassivmenu = get_terms("product_cat");
if (in_array("Агрохимикаты", $getMassivmenu)) {
echo "Нашёл Агрохимикаты";
}
if (in_array("Misc", $getMassivmenu)) {
echo "Нашёл Misc";
} else {echo "Ничего не нашел";}
print('<pre>');
var_dump ($getMassivmenu);
print('</pre>');
?>
Answer the question
In order to leave comments, you need to log in
Misc is the default category. In the wp settings, you can change it, for example, to "main directory" and then delete misc.
Misc is what kind of entity? Title? Then you need to get an array of headers and search in them
$getMassivmenu = get_terms(
'taxonomy' => 'product_cat',
'fields' => 'names'
);
if ( in_array( 'Агрохимикаты', $getMassivmenu ) ) {
echo 'Нашёл Агрохимикаты';
}
if ( in_array( 'Misc', $getMassivmenu ) ) {
echo 'Нашёл Misc';
} else {
echo 'Ничего не нашел';
}
vardump( $var )
function vardump( $var ) {
if ( current_user_can( 'manage_options' ) ) {
echo '<pre>';
var_dump( $var );
echo '</pre>';
}
}
You can look through the "Admin" in the categories of its id, and then in get_terms('exclude' =>id).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question