Hi Wietseneven.
Did you manage to get your solution for this? If so, are you able to share – or provide an example of the code you used?
I need a similar solution for State > Local Government Area > City/Town > Postcode
Thanks in advance.
Sorry John. Just further to the above, I need to be able to keep the database table’s relationship between the states, cities, towns, postcodes etc. Not sure how the Options page would deal with that?
Thanks John for your speedy reply. So, does this mean it is not at all possible to do the below – include a $wpdb query within the following function?
function acf_load_lga_field_choices( $field ) {
// reset choices
$field['choices'] = array();
global $wpdb;
$choices = $wpdb->get_results( "SELECT local_government_area FROM table_towns" );
// loop through array and add to field 'choices'
if( is_array($choices) ) {
foreach( $choices as $choice ) {
$field['choices'][ $choice ] = $choice;
}
}
// return the field
return $field;
}
add_filter('acf/load_field/name=local_government_area', 'acf_load_lga_field_choices');
I don’t understand how using Options page will help, or what I would need to do with cities/towns table from my database?
Can you please explain a little further, or provide another example, of how the Options page would work to dynamically populate ‘choices’ using existing database content. Thank you.
Hi Jonathon, Thank you for your assistance.
To clarify:
Part 1
I have put the functions part of the code (from here: sort a repeater field) in my functions.php file. I have replaced the field key with my relevant custom field key.
The part of this function that I don’t understand is this part:
add_filter('acf/load_value/name=scores', 'my_acf_load_value', 10, 3);
What do I need to change here, and to what?
And, do I repeat this function when I have more than one custom field to sort?
Part 2
Then I have put the php code within my single_custom_post_type.php file and replaced ‘repeater’ with my same field key as used in the function.
<?php if( have_rows('field_5650dfe9c5250') ): ?>
<ul>
<?php while( have_rows('field_5650dfe9c5250') ): the_row(); ?>
<li><?php the_sub_field('id'); ?>. <?php the_sub_field('name'); ?></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
I am not getting any result?
Where am I going wrong?
Hello. I also have a radio button sub field type within a repeater field.
Here is my code:
<?php if( have_rows('outcomes_your_activity_seeks') ): ?>
<?php while( have_rows('outcomes_your_activity_seeks') ): the_row();
// variables
$radio_1 = get_sub_field('radio_1');
$radio_2 = get_sub_field('radio_2');
$radio_3 = get_sub_field('radio_3');
$radio_4 = get_sub_field('radio_4');
?>
<p class=""><?php echo $radio_1; ?></p>
<p class=""><?php echo $radio_2; ?></p>
<?php endwhile; ?>
<?php endif; ?>
As I have a few of these custom field setups, is there way to code a loop that displays all sub fields based on the ‘Order’ ‘Label’ ‘Name’ ‘Type’ as opposed to having to put in each unique sub field name? This would prevent a lot of manual coding.
Also I don’t understand the different between get_sub_field and the_sub_field? One returns a value and the other displays – how are they different?
My website users are filling out the custom fields form in the WordPress Dashboard. All I need to do is display the content from the form in the front of the website.
Hoping there is a quick way to display the label + values of the choice/text/select/ sub fields?
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.