I see. Is it easy to convert admin pages to acf option pages?
I don’t believe this is an ACF option page. This is a page I made with the add_menu_page() and add_submenu_page() function calls. Are these still considered option pages?
Hi @deuxparquatre, thanks for the indepth post! I have a quick question on the ajax part. I am unfamiliar with the fetch function. Is that a php or wordpress function?
Oh dang, I just hopped back and saw the posts and currently reading through! So I have a quick question on the postid for update_field. Is there a post id for custom admin menu pages? When I look at the url, all it says is page=<page name>. I don’t see a numerical value that would correlate to a post id.
Thanks for responding Sam! So I’m currently trying to update the field with text input from a key and value input text box when a submit button is being pressed in an admin menu page. The field I’m trying to update is a text area. Here is the code:
<form action="" method="POST">
<input type="text" name="key" id="key">
<input type="text" name="value" id="value">
<input type="submit" name="Submit" value="send" >
</form>
<?php
if(isset($_POST['Submit']))
{
$key = $_POST["key"];
$value = $_POST["value"];
$array = array($key,array($value));
$out = json_encode($array);
update_field('field_key',$out);
}
?>
This is done from a custom admin menu page if that distinction helps.
Is there a particular way I need to use update_field when sending a json? I converted my array to json using json_encode and directly fed it to update_field with the field key, but I’m getting false.
I see. I’ll keep that in mind, thank you.
So just to make sure, if I want to save data to the field directly, do I use the update_field function? I’m trying to implement a save function within an admin page so I don’t have access to normal posts and such. This is all done in a php file.
I haven’t though of using a repeater so I’ll look into that. I have one last question. If I need to update an existing value in the field how do I go about it? Let’s say I have 5 different jsons in the field and I need to update the second one.
Yes, one requirement is editable fields which is why acf was chosen to host the data.
My end goal is to basically store data with a format of “id” to “list” in one field group. Do you know if this possible with acf?
Is it possible to have instead of an array a long string with commas in the field?
Ah, I see. I have another question. If I want to load the field group such that a specific text is associated to a certain array, do I use the load value hook?
Hi, sorry for the late reply. For the role bit, I was referring to the field group’s location rules. I’m assuming location rules defines who/where can access the field group.
Also, is there a function call to grab all the values in a field group in one go? So if I have two different fields in a field group, I can get an array of said values. Will this list be the same each time I call it as well?
Hi John,
I have 2 text fields in my field group. The field group is associated with user role at the moment, but that might change in the future to a admin menu page. If possible, I’d like to run a manual upload of the data at startup of the wordpress server since I just need to grab the data from this field group.
The main purpose of this field group is to keep data for a table to show which ids and names are related.
Hi John,
I took a look at the link and I’m a bit confused. I don’t see a way where I can dump data into a field group. In my field group, I have an id and name and I want to prefill this field group with data from a json.
Hi John,
Thank you for helping me!
Yes, I’m trying to load the field group for use on my site. I’m not looking to add fields nor add these fields to another field group.
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.