Support » Fixing WordPress » Return only child categories

  • Resolved Archie22is

    (@archie22is)


    Hi guys,

    I am using the default WordPress categories to create categories menu as indicated below:
    1)Sunglasses
    – Gucci
    – Levi’s
    – Ray Ban
    2) Sportswear
    – Adidas
    – Reebok
    etc.

    If one clicks on Sunglasses, they are taken to: http://www.site.co.za/categories/sunglasses -> and they are able to see all the sunglasses available on the website listed using <ul> and <li>.

    What I wish to accomplish:
    I want to have the ability to display descriptive sub-category next to the listed products. At the movement if I use the following method, it returns both the parent and the child (SportswearAdidas). I only want the child taxonomies – Adidas to be displayed.

    $pre_ids = get_the_terms($post->ID, 'category');
    $the_id = array();
    foreach ($pre_ids as $pre_id) {
    	if ($pre_id->parent ) $the_id[1] = $pre_id->name;
    	}
    var_dump ($pre_id);

    The above var_dump returns both the parent and child result this making it very difficult to filter and display only the child values.

    How should one go about solving the problem?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Return only child categories’ is closed to new replies.