ACF Field Not Showing On MEC Taxonomy Template

I have an ACF custom field which I have added to the MEC taxonomy template in the child theme. However, the field will not display on the public page.

Below is the template, saved in path/to/child-theme/

The added line is:

 <p><?php echo the_field('category_description_top'); ?></p>

The section of the MEC template is:

/**
 The Template for displaying mec-category taxonomy events
 @author Webnus <info@webnus.biz>
 @package MEC/Templates
 @version 1.0.0
 */
get_header('mec'); ?>
	
    <section id="<?php echo apply_filters('mec_category_page_html_id', 'main-content'); ?>" class="<?php echo apply_filters('mec_category_page_html_class', 'mec-container'); ?>">

    <?php do_action('mec_before_main_content'); ?>
    <?php do_action('mec_before_events_loop'); ?>

        <h1 class="mec-cat-h1"><?php echo single_term_title(''); ?></h1>
	
	    <p><?php echo the_field('category_description_top'); ?></p>
	
        <?php $MEC = MEC::instance(); echo $MEC->category(); ?>

    <?php do_action('mec_after_events_loop'); ?>
	
</section>

I have tried with and without “echo” in the line of code. Have I missed something?

Thanks,
Christopher

2022-05-24_09-31-37

Hey Christopher,

Thanks for reaching out!

Make sure that the category_description_top field is added correctly in the MEC taxonomy and please also make sure that the category_description_topis the correct field in ACF.

On the other hand, the credentials are not working and it leads me to be locked out, please double check the credentials. Please note that providing custom code is outside of our theme support, the reason why we are asking for the credentials is that we can check your settings properly.

Hope that helps and let us know how it goes.

Hi Marc,

Apologies for not being able to log in. I have checked the credentials and forced them to be as in the Secure Note. You should be able to login now.

Both the field in the MEC Taxonomy and in the template use the exact same name. There is a second ACF field which will also not display in the same MEC taxonomy template, even though I can get standard paragraph text to display.

Thanks,
Christopher

Hey Christopher,

I am afraid that the credentials are still not working, please check the secure note for more information.

Thank you.

It was a corrupt user profile. I have added a new user. Details in the secure note.
Thanks,
Christopher

Hey Christopher,

I already see why the ACF field is not showing on your MEC taxonomy. To display an ACF field in the taxonomy, you need to get the current taxonomy term. Please follow the documentation from ACF.

Instead of using <p><?php echo the_field('category_description_top'); ?></p>

your code must be:

<?php 

// get the current taxonomy term
$term = get_queried_object();

$category_top = get_field('category_description_top', $term); ?>

<p><?php echo category_top; ?></p>

Please note that providing custom code is outside the scope of our support. Issues that might arise from the use of custom code and further enhancements should be directed to a third party developer or you can avail One where we can answer questions outside of the features of our theme.

Hope that helps.

Hi Marc,

Thank you very much. That helped enormously. With a minor tweak it is working as hoped for!

<?php 
            // get the current taxonomy term
            $term = get_queried_object();
            $category_top = get_field('category_description_top', $term); ?>
            <p><?php echo $category_top; ?></p>

Many thanks for the great help,
Christopher

Hey Christopher,

You’re welcome! If you have any other concerns or clarifications regarding our theme features, feel free to open up a new thread.

Thank you.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.