Friday, November 18, 2022
HomeWordPress Developmentclasses - how do I exclude a class foreach

classes – how do I exclude a class foreach


I’ve this code and want to exclude a father or mother class with all subcategories related to it, are you able to assist me? I have been making an attempt to repair it for some time however I am unable to

    $cat_array = array();
            $classes = get_categories();
foreach($classes as $class) {
    $json_obj = new stdClass();
    $json_obj->id = $category->term_id;
    $json_obj->title = $category->title;
    $json_obj->slug = $category->slug;
    $json_obj->url = get_category_link($category->term_id);
    $cat_array[] = $json_obj;

}

That is the code and I am unable to even when I insert the class to be excluded within the array, I additionally tried this fashion however I am unable to:

        $cat_array = array('exclude_tree' => 38398);
                $classes = get_categories($cat_array);
    foreach($classes as $class) {
        $json_obj = new stdClass();
        $json_obj->id = $category->term_id;
        $json_obj->title = $category->title;
        $json_obj->slug = $category->slug;
        $json_obj->url = get_category_link($category->term_id);
        $cat_array[] = $json_obj;

    }

I am a little bit determined..

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments