Support

Account

Home Forums Feature Requests Change field query via Javascript API

Solving

Change field query via Javascript API

  • My scenario is, I have a repeater in which I’m selecting a custom taxonomy term, and then a custom post from within that term. The behavior I’m trying to achieve is to have the post object field filter to whatever term is selected in the taxonomy field. The current list of Javascript actions doesn’t include a hook to change a field’s query. Would it be possible to add a hook so that some aspects of a specific field could be changed, to include additional constraints on taxonomy or meta keys?

  • Hi @timothy_h

    Are you using the enhanced UI for the post object field? By that I mean is it loading in posts as you scroll or showing you all at once?

  • It’s loading posts as I scroll. I believe it’s the enhanced ui, it’s using select2 to build a searchable select.

  • Hi,

    Okay. I took a deep dive into how the ajax works for the post object field and it seems it’s actually calling the acf/fields/post_object/query action for the ajax querying.
    http://www.advancedcustomfields.com/resources/acf-fields-post_object-query/
    All the logic happens there.

    But I’m not sure you can do an add_filter from within an ajax call.. I don’t see a way around this to be honest.

  • Thanks for looking. That’s pretty much my conclusion when I was tracing through it. I was hoping that maybe I missed something or that such functionality could be added in a future version of ACF, where you could manipulate a field’s query via Javascript. The relationship field does something similar, but it’s kind of bulky for a repeater.

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

The topic ‘Change field query via Javascript API’ is closed to new replies.

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.