I am attempting to add a custom field to the product category taxonomy used by WooCommerce. Their term for the taxonomy is “product_cat” with an underscore in the term. This is presenting a problem when I am trying to retrieve the field as in:
$sm_hero_url = get_field('sm-category-hero-image', 'product_cat_' . $cat_id);
This creates the post id of ‘product_cat_87’. I think the extra underscore is the problem. The taxonomy comes from the plugin
Is there a work around for this?
Hi @studio34
Why is the ‘extra underscore’ a problem, I don’t understand.
I believe the extra underscore interferes with the parsing of the taxonomy_id string. This is the first time I have had to deal with a taxonomy that had an underscore in it and it is the first time that get_field has not worked for me.
I’m trying to rule out issues. I’ve already checked spelling. Not sure what else to try.
Hi @studio34
I don’t believe this underscore is an issue at all. There is no code in ACF which is exploding the $post_id string by the ‘_’ cahracter. Instead it looks in the wp_options table for a value with a options_name of:
'product_cat_' . $cat_id . '_' . $field_name
Perhaps you are having another issue but have jumped to this conclusion?
Let me know if I can be of any other help.
Perhaps you could test on another taxonomy just to rule this out?
It turns out it was an issue with WooCommerce’s function returning the correct taxonomy id. I appreciate the help and sorry for the false alarm.