[resolved] Return only child categories (2 posts)

  1. Archie22is
    Posted 3 years ago #

    Hi guys,

    I am using the default WordPress categories to create categories menu as indicated below:
    - Gucci
    - Levi's
    - Ray Ban
    2) Sportswear
    - Adidas
    - Reebok

    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?

  2. Archie22is
    Posted 3 years ago #


Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.