Home › Forums › General Issues › extract all checkbox values on a page
I have radio checkbox fields containing city names. I need to extract all values from this field, then display on the page only values that are contained in atleast one post of given category.
I know I can get these values with
<?php echo implode(', ', get_field_object('example')[choices]); ?>
and this is working fine on single article, but not in page.
I know that I should use
get_option('page_for_posts') in pages, but this never worked for me. I didn’t even set page for posts.
Any idea to extract this field on a page?
Sorry, I’ve read over your question several times and I can’t seem to work out what you’re trying to do by your explanation.
What post type is the field attached to? What page are you trying to display them on? Will need more specifics to figure out what you need.
Thank you for your reply. I’m sorry for my bad explanation and your lost time.
I have a radio button fields with city names. I’m trying to retrieve all of these values regardless of the selected one. I am able to do it with the code
<?php echo implode(', ', get_field_object('example')[choices]); ?> when I insert it in the single.php page of my template. The above code doesn’t work in page.php.
When I will be able to extract all these values in an array, then I will process them one by one to check if posts with the related city name exist and if true echo a link on the page.
Thanks in advance
Because you are on a page and not in the template that showss the posts you need to supply a post ID from a post that the field is attached to.
This means that the first thing you’re going to need to do is to get a post and set a valued for $post_id, then add that argument to the get_field_object call.
<?php echo implode(', ', get_field_object('example', $post_id)[choices]); ?>
I actually solved this simply by typing the field key instead of the field name. For future reference the field key can be found using this guide: http://www.advancedcustomfields.com/resources/get_field_object/
Thank you for your help
You must be logged in to reply to this topic.
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!
ACF wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG— Advanced Custom Fields (@wp_acf) March 16, 2023
© 2023 Advanced Custom Fields.