How to get the top level parent term Advanced Custom Field values in the child terms

Question

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
, moorewebx 1 year 2020-07-15T18:10:51-05:00 0 Answers 74 views 0

Leave an answer

Browse
Browse