Home › Forums › Feature Requests › Generic action buttons for ajax
My suggestion is a button that can be placed anywhere a normal field can. The button would trigger an AJAX request to admin-ajax.php with a specified action and optional parameters.
My use case for this was on a website that I made. The website utilized a very large amount of JSON for a Google Map. I cached the JSON in a file in my theme, but needed a way to update the file. I ended up creating an WP Admin page on my own but it made me think of this suggestion. I would have found it very convenient being able to place a generic button on an options page that sent a simple AJAX request for me.
When placing the button in some sort of context like on a custom post type page, you could have the option to include in the AJAX request some contextual data like the meta fields associated with the post.
I have yet to come up with more use cases other than refreshing cache but I am sure there are plenty.
Hi @brian1037
Altho it might not be the prettiest, if you want to put a button somewhere using ACF you can create a “message” field and add the button to that. You can put something like
<button type="button" class="button-secondary" id="my-ajax-trigger" data-action="myajaxaction">Trigger AJAX please</button>
in it.
I think your request makes sense in some cases but I think it’s too small of a use-case for it to be added to ACF core.. Of course you’re free to add it as an addon tho!
I can live with the Message field solution 🙂
If I had the skill I would create an addon but I’ll leave that to the pros.
Cool 🙂
ACF Actually makes it pretty easy to create new field types if you want to give it a shot. As long as you have decent code skills beyond HTML and CSS you should be able to work it out. you can read more here: https://www.advancedcustomfields.com/resources/creating-a-new-field-type/
Best of luck in your project!
The topic ‘Generic action buttons for ajax’ 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.