Home › Forums › General Issues › Conditional logic on Post Object
I’m trying to create a conditional field based upon whether a specific previous Post Object has been selected.
For example, imagine I have a post type called
Project Types which contains posts called
Project Type 1, and
Project Type 2.
Within ACF I would have a Post Object field to populate a list of all the
Project Types posts. However, I’d like to show an additional field, only when
Project Type 2 is selected.
Would this be possible?
It is doable. I believe you need the id of each project you want to be different. Once you have this, you set the conditional rules on the extra fields you want to come up with for your Post Object field to have a value greater than 1 below your ID and less than 1 more than your id. So if you had a post with an ID of 151 it would look like this
I did some digging and testing. I attempted to add “Selection is equal to” to the conditional logic on the post object field and I understand why it was left off.
When selecting is equal to ACF inserts a select field that has the choices set for check box, radio, select fields, etc.
When selecting > of < ACF inserts a number field.
As it stands, to use == there would need to be a whole lot of additional AJAX done in order to figure out what the “choices” could be.
I don’t know if this helps to explain it to others.
Since ACF does not know what the choices can be it cannot insert the select field. Adding < and > for a post object field was possible without a complete rewrite of the code involved. Adding = would require a complete rewrite of all the code involved for it with different things happening based on the the type of field the condition is set for. The only options added were those where the options that already existed would simply work without modification.
While using 2 items > and < to get a specific number is not pretty, it does work. More than likely when Elliot works out all of the issues with gooberbug we might see something better.
You must be logged in to reply to this topic.
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!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.