Get the featured image of an ACF relationship field

According to ACF documentation, a foreach loop is to be used to access the items in a Relationship field. Untested: $templates = get_field( ‘field_61318c078a746’ ); foreach ( $templates as $template ) { $template_image_id = absint( get_field( ‘Image’, $template ) ); $template_image_url=”https://example.com/fallback-image.jpg”; if ( ! empty( $template_image_id ) ) { $template_image_url = wp_get_attachment_image_url( $template_image_id, ‘large’ ); … Read more

How to get posts in backbone where a custom field matches a value?

The REST API endpoint “List Posts” (e.g. GET /wp/v2/posts) does not support filtering the posts by a post meta (or custom field), therefore passing post meta parameters like meta_key and meta_value will by default do nothing. But the rest_<post type>}_query filter can be used to manually add custom meta queries to the query arguments passed … Read more

Advanced Custom Fields – How do I get field values of a group within a group field type

I should not have been looping at all. This (not optimized) code fixes all issues and adds Difficulty. add_shortcode(‘get_run’, ‘get_run_status’); function get_run_status($atts) { $atts = shortcode_atts(array( ‘run’ => ”, ), $atts); $run_output=””; $diff_output=””; $found_day = false; $found_night = false; $run_atts = sanitize_text_field($atts[‘run’]); $run_query = get_field($run_atts); if($run_query): $run_status = $run_query[‘status’]; $run_difficulty = $run_query[‘difficulty’]; endif; foreach ($run_status … Read more

Redirect to File attached to a Post using ACF

The action redirect_to_acf_file_url doesn’t exist, at least not in stock WordPress. You’ll need to supply a proper action hook, and it’ll need to be one that happens before any output is sent to the browser. I’d recommend something like init or wp. add_action() takes a hook name and a function name. <?php function redirect_to_acf_file_url() { … Read more

How to conditionally display an ACF custom textarea contents only to those users chosen from an ACF User field

I’m quite new to this so I might be the wrong person to answer your question but: get_field(‘allowed_users’) Returns an array of user IDs so you can’t directly use in_array() So if you change the if statement to: if (is_array($allowed_users) && in_array($current_user_id, $allowed_users)) Hopefully it will work.

Create WhatsApp URL dynamically using ACF Pro from different fields

You can used ACF Pro and adding some custom code to your theme’s functions.php file. // Add ACF fields if( function_exists(‘acf_field_group’) ): acf_field_group(array( ‘key’ => ‘group_60aaf3a3f3d4a’, ‘title’ => ‘WhatsApp Fields’, ‘fields’ => array( array( ‘key’ => ‘field_60aaf3aaf3d4b’, ‘label’ => ‘WhatsApp Phone’, ‘name’ => ‘whatsapp_phone’, ‘type’ => ‘text’, ‘instructions’ => ‘Enter the WhatsApp phone number’, ‘required’ … Read more