• Hi,

    I’d like to know how to get the ID of the parent category when having sub-child categories.

    ——————–

    I want this:

    When in this category: \parent\child\child\

    or \parent\ or \parent\child\

    Give ID of: \parent\

    ——————–

    The code below only works for: \parent\child\

    ——————-

    $this_category = get_category($cat);
    // If category is parent, list it –>
    if ($this_category->category_parent == 0) {
    $menu_cat = $this_category->cat_ID; //cat_name
    $this_category->category_parent = $cat;
    } else {
    // If category is not parent, list parent category –>
    $parent_category = get_category($this_category->category_parent);
    $menu_cat = $parent_category->cat_ID; // cat_name
    // echo $menu_cat;

    ——————-

    I hope somebody understands and is willing to help. Thanks in advance.

Viewing 1 replies (of 1 total)
  • Thread Starter TheDyke

    (@thedyke)

    This determines wether this is a parent or not?

    ————–

    if ($this_category->category_parent == 0) {

    ————–

    But there should be the possiblity the “parent” is in fact child1, and I need parent1.

    \parent1\child1\child2\

    This makes sense?: (case: child2)

    ————–
    $parent = $this_category->category_parent;
    if ($parent->category_parent == 0 && $this_category->category_parent > 0) {

    ————–

Viewing 1 replies (of 1 total)
  • The topic ‘Get parent category when in \child\child\ category’ is closed to new replies.