0
votes

I'm curious why WordPress wouldn't support the parent->child hierarchy in tags taxonomy, so let's say if you have a tag:

Cities (which is parent) and this one will have the cities listed as child tags - London - New York - Moscow - ..... All the cities are child tags to the parent tag "Cities".

I think that this feature should be somehow overridden or implemented in some of the next WordPress versions.

In order to achieve the goal with this I've created a custom taxonomy and named it Tags, and the slug for this one is "post_tags1" so it wouldn't be conflicting with the original Tags.

Then I unset the default tags and I'm using the custom taxonomy post_tags1 as default tags taxonomy.

All the functions that are binded with tags wont work with the new one(is_tag, wp_tag_clound... etc)

instead of those functions you will have to use the terms functions as they apply to custom taxonomies.

I've reached my goal to create the parent-child hierarchy mentioned above, but when I'm trying to list the child tags of the parent tag, I get an empty array, but they exist in my taxonomy.

I'm using this code:

$taxonomies = array( 'post_tag1' );

    $args = array(
        'orderby'           => 'name', 
        'order'             => 'ASC',
        'fields'            => 'all', 
        'slug'              => 'cities',
        'parent'            => 'cities',
        'hierarchical'      => true, 
        'child_of'          => 0
    ); 

    $terms = get_terms($taxonomies, $args);
    var_dump($terms);
    foreach ($terms as $term) {
        print '<h2 class="story-heading">'.$term->name.'</h2>';
    } 

and the var_dump function prints an empty array, and in the foreach statement there is no iteration and nothing is printed.

Any idea why is that so??

Would appreciate if someone will propose a different approach to solve this or some sort of a plugin that will do the trick.

Regards, Mile M.

1

1 Answers

1
votes

Parent argument is an integer, so it should be the parent ID. From the get_terms function reference:

parent (integer) Get direct children of this term (only terms whose explicit parent is this value). If 0 is passed, only top-level terms are returned. Default is an empty string.