Home › Forums › Backend Issues (wp-admin) › How i get the checkbox list by database?
How i get the checkbox list by database?
I would like edit checkbox which checkbox will pull data from staff profiles custom post.How can I do it?
like this picture.
course infomation
https://www.dropbox.com/sh/be0c5d4cmqs3jnh/AAAJqJSsnqqxq_O1FUQURv-ra?dl=0
Hi @zinzoz
I’m afraid that I can’t see the image you have uploaded. Could you please upload it to a third-party service like Dropbox?
Regarding your question, did you mean you want to dynamically show the checkboxes? If you did, you could check this page: http://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/.
If you want to create a list of checked options, you can use something like this:
$values = get_field('checkbox_field_name');
$field = get_field_object('checkbox_field_name');
$choices = $field['choices'];
foreach ($choices as $value => $label) {
echo $label,': ';
if (in_array($value, $values)) {
echo 'checked';
}
echo '<br />';
}
If those are not the thing you want, could you please explain it to me again in more detail. Don’t forget to provide me with some screenshots 🙂
I hope this helps.
ok thanks sir^^ I have already submited on dropbox. The staff picture is custom post.
The coure1 picture is custom post which pull data from staff into meta-field ‘course information’. The meta-field type is checkbox at course1 picture.
I would like to pull data from staff post for pushing into meta-field ‘courseinformation’ .How can I do it? thank you very much>>
https://www.dropbox.com/sh/be0c5d4cmqs3jnh/AAAJqJSsnqqxq_O1FUQURv-ra?dl=0
Hi @zinzoz
For this kind of thing, I’d suggest you use the Post Object field instead. It’s easier and you can get the staff data if you need it later.
If you still want to use checkboxes, please take a look at this page: http://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/.
Instead of using get_field() to get the choices, you need to use the get_posts() function, loop over the returned posts and set the choices based on this data.
I hope this helps.
The topic ‘How i get the checkbox list by database?’ 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.