That was the issue, or at least part of it.
I had all the posts already created when I add the radio button to my order_block ACF group and for some reason, it just stopped passing the value: thought maybe it was naming (product_category); thought it was because all the posts already existed…
As soon as I changed it to a checkbox, everything came back, so I’m not really sure what’s going on.
Thanks for the quick response and great plugin! Nice parallax btw!
Greg
yeah thanks got it but i get another questions – how can i get a bridge between the keys and labels? so for example in the foreach
foreach( $label as $key => $value )
{
echo $key . ', ';
}
i want to echo so label as well as the key?

Hi @herrfischer
This is what you need to do:
1. Create a select field with the options
2. Write some jQuery to trigger a function on change of this select
3. Get the JS function to do an AJAX call to a WP ajax function
4. Create this WP ajax function in your functions.php
5. Get your JS to post the selected value to the php function
6. Get your php function to use this value to filter the posts and return the correct data
7. Get your js function to use this data on complete.
You will find a tutorial in the docs on querying the posts based on a custom field value, the rest is up to you and google.
Thanks
E
Hi, i’ve use update_field function but the data are not saved correctly, i’ve load my image with wp.uploadFile RPC Query and get the ID METADATA by $response[‘id’] with wp_get_attachment_metadata function; now i’ve create the array containing id, title, caption, url, sizes and so on… after that i’ve this code:
$value = get_field("field_5234c710a5b38", $post_id);
$value[] = $arrayPhoto;
update_field( "field_5234c710a5b38", $arrayPhoto, $post_id );
After that the gallery are empty, into db i see the field into wp_postmeta are different as a manual load, i’ve a metakey gallery (field_5234c710a5b38) with the serialized arrayPhoto (a:13:{i:0;a:9:{s:2:”id”;i:2272;s:3:”alt”;s:0:””;s:5:”title”;s:20:”import_1513072……), into other field generated by wordpress there are a serialized object with the ID of two metakey (_wp_attached_file and _wp_attachment_metadata) with the array of data (a:1:{i:0;s:4:”2182″;}).
How can i fix it?
Thanks
Awesome Elliot, that sounds good. Looking forward to resolving it!
Appreciate your quick reply.
-M
Hi Nuro, that’s a no on that but thank you for your suggestion.
It’s crazy. It seems so easy yet just doesn’t work.
Trying it normally with manual ID of page like:
<?php
$other_page = 890;
?>
<?php the_field('field_name', $other_page); ?>
…works great so the data IS being passed from the other page. I then had another idea of trying this way:
<?php
global $current_user;
get_currentuserinfo();
$username = $current_user->user_login;
$other_page = $username;
?>
<p><?php the_field('favourite_movie', $other_page); ?></p>
…which didn’t work either.
The username of the current user IS also working when I ask for it conventionally:
<?php global $current_user;
get_currentuserinfo();
echo 'Username is ' . $current_user->user_login . "\n";
?>
Baffled.
Elliot, how can I debug this? I’ve tried dumping the values:
<?php
global $current_user;
get_currentuserinfo();
$other_page = $current_user->user_login;
$values = get_field('favourite_movie');
var_dump($values);
?>
and get bool(false) printed out?

It looks like you are using a text field for the hair_color field rather than a select/option field.
So try any of these:
<?php
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
$hair_color = get_field('hair_color', $taxonomy . '_' . $term_id);
echo $hair_color;
?>
<?php
global $post;
$taxonomy = "someting";
$terms = get_the_terms($post->ID, $taxonomy);
if( !empty($terms) )
{
$term = array_pop($terms);
$custom_field = get_field('hair_color', $taxonomy . '_' . $term->term_id );
// do something with $custom_field
}
?>
See this example for more info: http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-a-taxonomy-term/
If you do want to use a Radio Button field type and have them choose from a list of hair colors, then this might work too (I think):
<?php
$field = get_field_object('hair_color', $taxonomy . '_' . $term->term_id);
$value = get_field('hair_color');
$label = $field['choices'][ $value ];
echo '<p>' . $label . '</p>' ;
Probably didn’t work before due to being text field rather than select/radio field and the $taxonomy value not being defined, although not sure…

Ok, managed to solve it by swapping the SQl round a little, like so:
$rows = $wpdb->get_results($wpdb->prepare(
"
SELECT *
FROM wp_postmeta
WHERE meta_key LIKE %s AND meta_value LIKE %s ORDER BY meta_value ASC",
'dates_%_available_dates', ''.$year.''.$month.'%',
""
));
Hi,
Thank you, but I get an empty value.
a var_dump($field) is empty too.
This is the return:
array(17) { [“key”]=> string(16) “field_hair_color” [“label”]=> string(0) “” [“name”]=> string(10) “hair_color” [“type”]=> string(4) “text” [“order_no”]=> int(1) [“instructions”]=> string(0) “” [“required”]=> int(0) [“id”]=> string(20) “acf-field-hair_color” [“class”]=> string(4) “text” [“conditional_logic”]=> array(3) { [“status”]=> int(0) [“allorany”]=> string(3) “all” [“rules”]=> int(0) } [“default_value”]=> string(0) “” [“formatting”]=> string(4) “html” [“maxlength”]=> string(0) “” [“placeholder”]=> string(0) “” [“prepend”]=> string(0) “” [“append”]=> string(0) “” [“value”]=> bool(false) } 3
Thanks

Something like this might be what you’re looking for:
<?php
$rows = get_field('repeater');
if($rows) {
echo '<h3>Results</h3>';
echo '<ul>';
$row_count = count($rows);
$i = rand(0, $row_count - 1);
while(has_sub_field('repeater')) {
$field = get_sub_field_object('img_title');
$value = get_sub_field('img_title');
$label = $field['choices'][ $value ];
echo '<li><a href="' . $rows[$i]['img'] . '">' . $rows[$i][$lable] . '</a></li>' ;
$i++;
}
echo '</ul>';
}
?>

Hi @Cyril
Perhaps this feature request needs to be explained in detail. I’ll try my best to recommend a solution.
Thanks
E

Hi @istrasoft
Great feedback. Yes. I will look into this and perhaps find a way to create a ‘default’ WP_Query value to solve the issue perfectly.
I know you can hook into the SQL sort statement and write a CASE where you can define values that don’t exist, but I will need to trial this code before mentioning it.
Cheers
E

Hi @figureone
Thanks mate. I really appreciate your help on this one, even though I can’t offer a quick solution.
Yes, I think the best solution is to offer an option for the field. But perhaps we could do this as a ‘non UI’ option such as a filter for the wysiwyg field.
Something like:
<?php
apply_filter('acf/fields/wysiwyg/strip_slashes', 'my_wysiwyg_strip_slashes', 10, 1);
function my_wysiwyg_strip_slashes( $strip_slashes )
{
// default is true
$strip_slashes = false;
return $strip_slashes;
}
?>
I’ll add this to the to-do and re-read over this entire thread to make sure I haven’t missed something.
As for timings, I’m extremely busy for the next 2 weeks, but then I’m going back to full time dev on ACF! So this will definitely be introduced into the core soon.
Thanks a million
Cheers
E

You can also name a select field $footer with options yes/no. Then just do a conditional statement based on the $footer value.
<?php
if(get_field('$footer') == "yes")
{
//...
} else {
//...
}
?>
or just
<?php if( get_field('$footer') ): ?>
//...
<?php endif; ?>
As far as returning null, you can skip the option to show the footer and just check if data has been entered into each of the footer column fields. If no, the field wont show.
<?php
$col_1 = get_field('$footer_col_1');
$col_2 = get_field('$footer_col_2');
$col_3 = get_field('$footer_col_3');
if($col_1) {
echo $col_1;
}
if($col_2) {
echo $col_2;
}
if($col_3) {
echo $col_3;
}
?>
Lots of options, so just go with the method that works best for you.
Thanks Elliot,
My question was not ony a display matter. The goal behind these “multiple fields in one” is to build with a few clics a potentially very complex UI, coupled to specific validation rules and treatments.

Perfect! I will give it a try. Thanks Elliot!
Thanks Nuro. The opening tag was there but I hadn’t copied it in.
Anyway, I seem to have solved this problem now. I hadn’t switched on debugging mode and when I did a few errors came up – one about automatic feed links and another about how I had enqueued jquery. I’ve sorted these out and now get_field() is working.
I now have another issue where I can’t add more than one item in my repeater field (which I had been able to before) but if I can’t sort that out I’ll start up another topic.
Thanks again,
Elizabeth
Hi @elliot and thanks for your information.
I investigated and here are the results. They may be useful to a future person that has the same issue, or maybe to enhance ACF a bit.
I switched the field type from True/False to Radio, where I was able to provide two text values ‘yes’ / ‘no’ and defined ‘no’ to be the default value.
However, the WP_Query still only returned the same, and then it hit me. The problem was not what I thought. Actually, I had already 250 articles, and when adding a new custom field through ACF, unless each article is manually edited and updated, the custom field is not listed at all in the meta data of that article. This does not depend on the actal value or default value of the field.
So, what would be a nice to have feature is that when adding a new field, having a button or some action link that would allow to set the default value for this new custom field, on all items using this field set, and which have no value for that field at all. Also, adding a little note about this behaviour into the documentation on the queries would help the newbie user to realize how it works.
Thanks ๐
In typical fashion, I got there in the end! This is what I ended up using in my template files:
<?php $image = get_field('field_name'); ?>
<img src="<?php echo get_template_directory_uri(); ?>/images/loader.gif" alt="" data-src="<?php $image = get_field('field_name'); echo($image['sizes']['custom-size']); ?>" data-src-retina="<?php $image = get_field('field_name'); echo($image['sizes']['custom-size-retina']); ?>" />
And to the functions.php with these declarations:
add_image_size( 'custom-size', 300, 300, true ); // Standard pixel density
add_image_size( 'custom-size-retina', 600, 600, true ); // Double pixel density
Yes, sorry for the confusion of my question.
I thought it served the same code for both, regardless of the multiple-choice factor.
But his indication was perfect to find the code I needed.
It had been several times and select the checkbox documentation but I could not understand.
Now it works perfect for single or multiple value select and checkbox.
<?php
if( in_array( 'red', get_field('colors') ) )
{
echo '<span class="red"></span>';
}
if( in_array( 'green', get_field('colors') ) )
{
echo '<span class="green"></span>';
}
?>
Thanks for your help

This should work:
– Create a Field Group
– Add a Repeater
– Add Sub Fields to Repeater
– Add two Radio Button Fields to Field Group (Not as sub fields in the repeater!)
I have these fields in my Field Group:
“Repeater” => Repeater Field
“IMG” => Repeater Sub Field, Field Type = Image, Return Value must be “Image ID”
“IMG Title” => Repeater Sub Field, Field Type = Text
“Row Sort” => Field Type = Radio Button, Default Value = “default”, Choices are set to:
default : default
random : random
reverse : reverse
“Row Limit” => Field Type = Radio Button, Option “Add ‘other’ choice to allow for custom values” is checked. Default Value = “3”, Choices are set to:
1 : 1
2 : 2
3 : 3
When the user creates a post, they can limit the number of Repeater rows to show and choose how the rows should be sorted (e.g. Random Order + Displaying 5 Rows).
Tested and works, could probably clean code up or do some of it differently… this is what my tired mind came up with ๐
<?php
$row_sort = get_field('row_sort' ); // radio button: random/reverse/default
$row_limit = get_field('row_limit'); // radio button: 1/2/3/Custom
$rows = get_field('repeater' );
$sub_field = has_sub_field('repeater');
$img = get_sub_field('img');
$img_title = get_sub_field('img_title');
if($rows) {
echo '<h3>My List</h3>';
echo '<ul>';
for($i=0; $i < $row_limit; $i++) // Limits Rows based on field "Row Limit"
{
if($row_sort == "random") { // Random Order
/* Display Images Randomly (e.g. If 10 images have been added and Row Limit is set to 5, 5 Random Images will Display), $image[0] will pull the image links */
$rand_row = $rows[ array_rand( $rows ) ];
$rand_row_image = $rand_row['img' ];
$image = wp_get_attachment_image_src( $rand_row_image, 'full' );
echo '<li>';
echo $image[0]; // Return Value for Image must be set to "Image ID"
echo '</li>';
} elseif($row_sort == "reverse") { // Reversed Order
/* Displays links to images in reversed order. If 10 images and Row Limit is set to 5, Images 10, 9, 8, 7, 6 will display */
$rowArray = get_field('repeater' );
$reversedArray = array_reverse( $rowArray );
if($reversedArray) {
$reversedArray = has_sub_field('repeater');
$img = get_sub_field('repeater');
$img_title = get_sub_field('repeater');
echo '<li><a href="' . $img . '">' . $img_title . '</a></li>';
}
} else { // Default Order
/* Displays list of Image Titles like it normally would, but limited to Row Limit */
$default = get_field('repeater' );
$default = has_sub_field('repeater');
if($default) {
$img_title = get_sub_field('repeater');
echo '<li>' . $img_title . '</li>';
}
}
}
echo '</ul>';
} ?>

Good news. I have just added and pushed to github an update for the taxonomy field.
This update contains a new filter allwoing you to customize the args used in the wp_list_categories function.
You can use it like so:
add_filter('acf/fields/taxonomy/wp_list_categories', 'my_taxonomy_args', 10, 2);
function my_taxonomy_args( $args, $field )
{
// do stuff to $args
return $args;
}
Hey @elliot,
I understand server setups are varied, so lets not waste any more time trying to tackle the problem by identifying which ones have problems with magic quotes.
Instead, let me show you how ACF doesn’t work on one of the most common server setups, Ubuntu 12.04 LTS (it’s the standard image on Amazon EC2 and linode). Here are some steps I took to reproduce the ACF bug under this setup:
* I created a test VM environment (Ubuntu 12.04 LTS, PHP 5.3.10, MySQL 5.5.32).
You can do this easily in vagrant–Ubuntu 12.04 Precise 32bit is the default vagrant box. Instructions on setting up a vagrant virtual machine on your computer is available here:
http://docs.vagrantup.com/v2/getting-started/
* I installed a vanilla copy of WordPress 3.6.1 and ACF 4.2.2.
* I created a new ACF Field Group, and added one Wysiwyg Editor field to the field group. I left all defaults as-is, so the field group appears on all posts on the site.
* I then edited the sample post included with WordPress (“Hello world!”), and added the following content to the new ACF field:
Hi! This is ACF content. It just might strip out \ backslashes, which could be \nasty.
* I then saved the post (by clicking “Update”), and confirmed that the backslashes (“\”) were removed from the above text.
In short, I think you haven’t heard about this issue from others because the backslash is a lightly used character, and tracing this issue back to ACF is time consuming. But any data loss issue should be treated seriously.
The easiest solution for you, I think, is to implement another option in the Settings panel for a Wysiwyg field. This setting would simply toggle whether stripslashes_deep() gets called or not. If we do it that way, we don’t have to use get_magic_quotes_gpc() at all, so you shouldn’t get any reports from other users on older PHP setups. This option would default to the current behavior if you wish, so it doesn’t change the default behavior, but it would give me and any others running newer PHP setups the ability to prevent ACF from haphazardly removing backslashes from all ACF wysiwyg content.
I can provide the pull request with this code, so you don’t have to take extra time writing it. I simply need some sort of assurance that you’ll implement it before I take the time to write the code.
Cheers,
-Paul
PhD Information Science
College of Education
University of Hawaii
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.