Support

Account

Home Forums General Issues Loop through child product categories and change names using text field

Unread

Loop through child product categories and change names using text field

  • Hi,

    On our website, we are wanting to loop through all the children of a specific product category and then display all the children ofsaid category.

    So far we are able to display all the children fine, however, for SEO purposes we feel it would be helpful to be able to alter the names of the child categories for display.

    For instance, say we have a category called ‘Large Umbrellas’, we want to be able to edit its name to ‘Umbrellas’ and then have the edited name display on the parent category. Hope this makes sense.

    Here is how far we’ve got with the code so far.

    $terms = get_terms([
        'taxonomy' => get_queried_object()->taxonomy,
        'parent'   => get_queried_object_id(),    
    ]);
        
        
    $grade = get_field('custom_cat_title', 'product_cat' . '_' . $terms);
    
    echo '<ul class="basel-product-categories">';
    foreach ( $terms as $term) {
        echo '<li class="cat-item"><a href="' . get_term_link( $term ) . '">' . $term->name . '</a></li>';  
    }
    echo '</ul>';
    echo $grade;
    }
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.