1

I am using Advanced custom fields in my product_cat taxonomy to display fields on my product category pages. I would like to be able to edit the top parent product category and have those changes reflected on both the parent and child pages.

Here is the current code I am working with:

add_filter('ocean_after_page_header', 'woo_product_cat_header');
function woo_product_cat_header( $src ) {
    // ///////////////  CHEMICALS
     if (is_product_category()) {  
        $term = get_queried_object();
        $img_url = get_field('category_image_placeholder', $term);
        $description = get_field('category_description', $term); ?>

    <div class="woo-cat-page-header" style="background-image: url('<?php echo $img_url?>');"></div>

    <div class="container">
        <div id="woo-cat-description">
            <?php echo $description;?>
        </div>
    </div>
    
<?php } elseif ( has_term( 'other-category-here', 'product_cat' ) ) {
echo 'Something else';
}
  return $src;
}

As I understand it I need to change the $term = get_queried_object(); to something like:

function get_term_top_most_parent( $term_id, $taxonomy ) {
    $parent  = get_term_by( 'id', $term_id, $taxonomy );

I cannot figure this one out. Thanks

0

Could look into using get_ancestors();. It will get an array of all of the ancestors of the item in order from lowest to highest.

See: https://developer.wordpress.org/reference/functions/get_ancestors/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.