This worked for me to get the taxonomy terms for the current post with an ACF icon field attached:
<?php $terms = get_the_terms( get_the_ID(), 'project_services' );
$cat_icon = get_field('icon', $queried_object);
?>
<?php if( $terms ): ?>
<ul class="menu">
<?php foreach( $terms as $term ): ?>
<li>
<a href="<?php echo get_term_link( $term ); ?>">
<?php $icon = get_field('icon', $term->taxonomy . '_' . $term->term_id);?>
<img src="<?php echo $icon ?>">
<?php echo $term->name; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
In what sorry?
Haha yes definitely activated, im pretty stupid but not that stupid lol.
I did see on another thread someone else having the same issue.
Has anyone found a solution to this? Does the plugin @twgerard created no longer work?
@exnihilo_maxime This is the whole code I am using
$GLOBALS['wc_loop_variation_id'] = null;
function is_field_group_for_variation($field_group, $variation_data, $variation_post) {
return (preg_match( '/Variation/i', $field_group['title'] ) == true);
}
add_action( 'woocommerce_product_after_variable_attributes', function( $loop_index, $variation_data, $variation_post ) {
$GLOBALS['wc_loop_variation_id'] = $variation_post->ID;
foreach ( acf_get_field_groups() as $field_group ) {
if ( is_field_group_for_variation( $field_group, $variation_data, $variation_post ) ) {
acf_render_fields( $variation_post->ID, acf_get_fields( $field_group ) );
}
}
$GLOBALS['wc_loop_variation_id'] = null;
}, 10, 3 );
add_action( 'woocommerce_save_product_variation', function( $variation_id, $loop_index ) {
if ( !isset( $_POST['acf_variation'][$variation_id] ) ) {
return;
}
$_POST['acf'] = $_POST['acf_variation'][$variation_id];
acf()->input->save_post( $variation_id );
}, 10, 2 );
add_filter( 'acf/prepare_field', function ( $field ) {
if ( !$GLOBALS['wc_loop_variation_id'] ) {
return $field;
}
$field['name'] = preg_replace( '/^acf\[/', 'acf_variation[' . $GLOBALS['wc_loop_variation_id'] . '][', $field['name'] );
return $field;
}, 10, 1);
and this is line 148
acf()->input->save_post( $variation_id );
Im not sure i just used your code at the top of the page? I didnt add anything else? Was I supposed to?
Thanks
John
Hi @exnihilo_maxime .
Thank you very much for your reply.
This is the error shown in the logs:
2019-09-17T07:57:27+00:00 CRITICAL Uncaught Error: Call to a member function save_post() on null in /home/customer/www/nevelli.creativepatricktesting.co.uk/public_html/wp-content/themes/nevelli/functions/theme-support.php:148
Stack trace:
#0 /home/customer/www/nevelli.creativepatricktesting.co.uk/public_html/wp-includes/class-wp-hook.php(286): {closure}(22, 0)
#1 /home/customer/www/nevelli.creativepatricktesting.co.uk/public_html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array)
#2 /home/customer/www/nevelli.creativepatricktesting.co.uk/public_html/wp-includes/plugin.php(465): WP_Hook->do_action(Array)
#3 /home/customer/www/nevelli.creativepatricktesting.co.uk/public_html/wp-content/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php(532): do_action('woocommerce_sav...', 22, 0)
#4 /home/customer/www/nevelli.creativepatricktesting.co.uk/public_html/wp-content/plugins/woocommerce/includes/class-wc-ajax.php(2084): WC_Meta_Box_Product_Data::save_variations(14, Object(WP_Post))
#5 /home/customer/www/ in /home/customer/www/nevelli.creativepatricktesting.co.uk/public_html/wp-content/themes/nevelli/functions/theme-support.php on line 148
@exnihilo_maxime I can add the fields but I cant save the data that I put in them. I just get an infinite spinner and the below error in the console:
wp-admin/admin-ajax.php 500 (Internal Server Error)
Any suggestions would be really appreciated.
Thanks
John
@gila-monster Thanks for you advice.
My fields are displaying in the back end under my product variations and the data is saving correctly but I cannot work out how to show the fields on the front end of my website?
Do you display them in the same way as you normally would ACF fields? e.g.
<?php the_field(‘text’); ?>
@shaun I can add my fields and save them but I cant see them on the front of my website? Are they displayed in the same way as a normal ACF field?
@dynostudios I am having this exact same issue. Did you ever resolve it?
Thanks
John
@exnihilo_maxime I can add the fields but I cant save the data that I put in them. I just get an infinite spinner and the bellow error in the console:
wp-admin/admin-ajax.php 500 (Internal Server Error)
Any suggestions would be really appreciated.
Thanks
John
Thanks for your post.
When I use this code my fields appear on my product page but when I add anything to them they dont save, I just get a spinner going round forever.
I just wondered if you had any ideas why this might be happening?
Thanks
John
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.