Home › Forums › Feedback › Consider filtering get_option calls to support get_option use for termdata
The new version of ACF 5.5 changes the way terms are stored, from the options table -> the new termmeta table.
A db upgrade occurs, so all is well and good if you’re using (as you should be) get_field
to get the ACF term meta.
However, it seems as if there are many developers who bypass get_field and have been getting the data via get_options
. This will still work for term meta added before 5.5, but not after.
Although they shouldn’t be doing this, there will be many themes / plugins that break or stop working. I think it would be a good idea to add a filter to get_option calls
to detect when an old option is queried and transparently query termmeta
instead – it probably wouldn’t take long to do, and would have quite a big impact in terms of perception and help for the community.
Because get_options()
is a WordPress core function, I’m afraid there’s nothing we can do with it. By using that function instead of the get_field()
, the developer should be aware of the limitation of the function.
A workaround for that is you can try using the “option_” hook to alter the data. So if your taxonomy slug is “customtax”, the term ID is “99”, and the field name is “field_name”, then you can do it like this:
add_filter( 'option_customtax_99_field_name', 'my_alter_option' );
function my_alter_option($option){
// do something here
// return
return $option;
}
I hope this makes sense 🙂
Because get_options() is a WordPress core function, I’m afraid there’s nothing we can do with it.
James, it’s fairly straightforward. You’d just have to intercept the term_id
within get_field
and pass that through a get_option
filter.
add_filter ('get_option', 'acf_bc_term_meta');
with a function looking for _category_id_name
.
Pippin has some code which will do almost exactly what’s required, swapping post_meta
for options
: https://github.com/easydigitaldownloads/EDD-Commissions/blob/master/includes/commission-functions.php#L828
If I’m not mistaken, I believe @digitalquery said that the developers are using the get_option()
function, not the get_field()
function. This means that the data is retrieved directly from WordPress without any interference from ACF. Maybe I missed something here. If I did, could you please explain it to me in more details?
Also, I’m afraid I can’t find any documentation regarding the ‘get_option’ filter. Would you kindly share it with me so I can try to find another solution for this issue?
But if you guys think ACF should be able to modify the get_option()
function, you can always open a new ticket so this request can be passed directly to the plugin author? You can open a new ticket here: https://support.advancedcustomfields.com/new-ticket. Also, please don’t forget to explain the issue again.
Thanks 🙂
when will be availble the version, that uses termmeta instead of options table? I want to make the fields translatable / synced with polylang and it is now not possible
The topic ‘Consider filtering get_option calls to support get_option use for termdata’ is closed to new replies.
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.