You might want to have a look at the Calculated Fields for ACF plugin that most likely will solve this issue for you without writing any PHP code.
https://wordpress.org/plugins/calculated-fields-for-acf/
Looks like you’re declaring and assigning a value to $otaname on row 5 in your snippet. But then you never actually use that variable?
Also. You use the variable $ota in your series of if-statements. The way your code is written, you’re assuming that it has a string value. But on each of the conditional statement blocks, you also output $ota[‘label’], assuming $ota is an array.
My best guess is that you’ve mixed up $ota and $otaname in your code.
For future reference, this type of functionality is included in the plugin “Calculated fields for ACF”. Available for free on the WordPress plugin repo.
Hi,
You don’t explicitly say what’s wrong with the results you’re seeing. But I can think of a few reasons that you don’t see the results you’re expecting. The most obvious one is the call to get_posts.
In the args array passed to get_posts, you don’t specify ‘numberposts’. If you leave it out, it will default to 5. If you want all posts, you need to specify -1. Please se https://developer.wordpress.org/reference/functions/get_posts/ for details.
Hi,
Since beginning of December (a week ago), there’s a free plugin on the WordPress plugin repository that aims to solve this exact problem. It’s called Calculated Fields for ACF. From your description above, I think this plugin can solve your problem without having to write code.
https://wordpress.org/plugins/calculated-fields-for-acf/advanced/
Hi,
Since beginning of December (a week ago). There’s a free plugin on the WordPress plugin repository that aims to solve this exact problem called Calculated Fields for ACF. From your description above, I think this plugin can solve your problem without having to write code.
https://wordpress.org/plugins/calculated-fields-for-acf/advanced/
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.