Advanced custom field – gallery – display one random image

Shouldn’t you be doing something like this? <img src=”https://wordpress.stackexchange.com/questions/99655/<?php echo $rand[“url’]; ?>” alt=”https://wordpress.stackexchange.com/questions/99655/<?php echo $rand[“alt’]; ?>” /> Update I’m not really familiar with that plugin (stuff could be happening behind the scenes) but here’s a better guess than my previous one: <?php $gallery = get_field(‘gallery_home’); $rand = array_rand($gallery, 1); if( $gallery ): ?> <img src=”https://wordpress.stackexchange.com/questions/99655/<?php … Read more

Get the label from ACF checkbox [closed]

You can try this $field = get_field_object(‘color’); $colors = get_field(‘color’); // array of selected color values foreach($colors as $color){ echo “selected color: “. $color. ” with label: ” . $field[‘choices’][ $color ]; } where the labels are fetched by get_field_object according to the link you provided. You could also use print_r() or var_dump() to check … Read more

WP REST API: Order posts by meta value (acf)?

I’m guessing you haven’t exposed meta_key and meta_value to the REST API with the rest_query_vars filter, so this should do it: function my_add_meta_vars ($current_vars) { $current_vars = array_merge ($current_vars, array (‘meta_key’, ‘meta_value’)); return $current_vars; } add_filter (‘rest_query_vars’, ‘my_add_meta_vars’); Then you can refer to meta_key and meta_value in your query. Be aware that this obviously exposes … Read more

Returning all radio button options when using Advanced Custom Fields

Check out this page in order to discover your field key for your radio button: http://www.advancedcustomfields.com/docs/functions/get_field_object/ Next, insert this code where you are grabbing your field values: <?php $key = ‘your_fieldkey_here’; $field = get_field_object($key); if ($field) { foreach ($field[‘choices’] as $key => $value) { echo (‘KEY : ‘ . $key); echo (‘<br />’); echo (‘VALUE … Read more

Adding a body class with ACF

Hook into the body_class filter and add your field there. It might be better to get the ID from get_queried_object_id() instead of get_the_ID(). add_filter( ‘body_class’, ‘wpse_20160118__body_class’ ); function wpse_20160118__body_class( $classes ) { if ( $package_colour = get_field( ‘package_colour’, get_queried_object_id() ) ) { $package_colour = esc_attr( trim( $package_colour ) ); $classes[] = $package_colour; } return $classes; … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)