Support

Account

Home Forums Feature Requests Filters: More flexible load_field and load_value. Having the context data

Solved

Filters: More flexible load_field and load_value. Having the context data

  • Hi and thanks!

    I’ll try to describe my situation, which I saw repeating for some others. I might miss something big here, so let me know please. For this fields structure:

    – F1: post id field (post selection)
    – F2: flexible field (many entries)
    — F5: select box (or a relations field)

    1. I want to populate the select box (F5) according to the post id (F1) field. I could do it, but it wasn’t natural to ACF, because there is no way to find what was the (F1) value. It’s *very important*
    Ajax solutions are not desired and make no sense in many cases.

    2. The (F5) choices are populated dynamically. Each (F5) instance has different values, based on some fields under (F2). For each flexible field row, the choices should be different, yet the the choices for (F5) are generated once for all rows – that makes no sense.
    Not only that, but again, as in (1) it’s hard again to know what were the values

    =

    So, more flexibility:
    for 1. I think you should consider allowing people to get the context data when loading the data somehow – either by doing another round of load_field filter (‘post_load_field’) which should applied after the values have been loaded (otherwise, we don’t know what they are)

    for 2. Not sure what can be done within the architecture limits, but I think that when you have multiple rows in a repeater/flexible field, it makes sense to be able to populate same fields with different selectable data

    Thoughts?

    Thanks!

  • Case 1) Loading one field on the PHP side base on another field makes little sense without using AJAX, simply because new fields have no value and this means that the post must be saved every time F1 is change in order to change F5. In order for ACF to update F5 it would have to make that AJAX request.

    Case 2) The problem with case 1 multiplies the issue for case 2. Being generated in PHP and knowing how ACF works, it simply isn’t possible to show different choices in different instances of the same field, at least not in PHP. Using JavaScript, this is possible.

    ACF can do some complex things but I don’t think what you’re looking for will ever be possible without doing quite a bit of custom JavaScript and AJAX coding. Then again I’m not the developer.

  • Thanks for the answer and time – really appreciates it

    1. It does makes sense, at least in my case. Yes, you have to save, but then you can use it over and over, over very similar posts (duplicated, for example)

    2. You have data to judge by, perhaps complex. You can save once and have the right fields auto populated. No need for multiple ajax calls each time, which also costs in performance (remember, this happens for front end too)

    It seems to me to have a lot of sense to have the context, the least. Why would you allow this? it literally costs nothing.

  • If you are okay with needing to save the post in order for the choices of other fields to be generated properly then this can be done with the standard acf/load_field filter.

    PHP could also be used to have different values in different rows of a repeater, but it is far more complicated. First, the repeater rows would need to exist when you saved the post. Then when each row of the repeater is loaded you can use other functions, for example there is a function in ACF that gets the parent of the current field, you can get the values in parent fields and set the values of individual rows. It would be a fairly complicated process, but it could be done. Personally I’d find it easier to do it with JavaScript and a little AJAX where needed.

  • Thanks!

    Yes, you can get the parent field object, but it won’t help you load different option for each row, because the “load_field” fired only once..

    Plus, the field parent is the field object, meaning, the field post in the wordpress DB, not the actual row with specific data.

  • You might try using the acf/prepare_field filter https://www.advancedcustomfields.com/resources/acfprepare_field/, but like I said, the repeaters will need to already exist, I think. And you should be able to get the value for a parent field. I don’t know the steps involved in doing so, but it should be possible.

  • you’re right, I totally missed that one :\ Thanks!

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.