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

ACF: get_field() returning false [closed]

You need to pass in the ID of the post you’re trying to get the field from: Eg get_field(‘display_featured_image’, $post_id). In a loop you could do get_field(‘display_featured_image’, get_the_id()); ACF Stores field data in wp’s meta_fields, so you could even use WP’s built in meta handler to pull the data yourself Eg: get_post_meta( $post_id, ‘acf_field_name’, true); … Read more

Advanced Custom Fields select field : How to echo the label, not the value? [closed]

The get_field_object() function requires the field KEY not the field NAME. See docs: http://www.advancedcustomfields.com/resources/functions/get_field_object/ So it should looks something like this… $field = get_field_object(‘field_53d27f5599979’); $value = get_field(‘field_myfield’); $label = $field[‘choices’][ $value ]; You can find the field key by clicking on “Screen Options” > “Show Field Key” and it should appear next to the field … Read more