Xavi van der Wouden
Xavi van der Wouden

Reputation: 21

How can I display acf metadata array in revolution slider

i'm trying to build a movie slider for a Cinema tv screen. I started to build custom Fields using acf advanced custom fields in wordpress.

Everything is working except displaying acf metadata with more options. The revolution slider and the grid now displays it like the word (array) image displaying array this is what I use to display custom fileds in the sliders

**in cornerstone**  
{{acf:field_name}}

**in sidebar**
 [acf field="field_name"]

**in the grid**
#meta:field_name#

**in revolution slider** 
{{meta:field_name}}

**in template**
*// simple*
<?php the_field('field_name'); ?>

*// multiple options*
<?php
	// vars
          $values = get_field('field_name');

          // check
          if( $values ): ?>
              <ul>
                 <?php foreach( $values as $value ): ?>
                  	<li><?php echo $value; ?></li>
                  <?php endforeach; ?>
               </ul>
          <?php endif; ?>

How can I make this work so it displays more options, like on the template page

Can somebody please help me

Upvotes: 2

Views: 6076

Answers (2)

Armstrongest
Armstrongest

Reputation: 15419

This is a work around, but you could do the following...

Assuming your image field is called my_image and it's set to return a URL, create a new url field named my_image_url

In functions.php write the following code:

function acf_post_onsave($post_id) {

  // update url field
  $image_url = get_field('my_image') ?? null;
  if($image_url){
    update_field('my_image_url', $image_url, $post_id);
  }
} 
add_action('acf/save_post', 'acf_post_onsave', 30);

It's not the prettiest solution. Also, since my_image_url will always be dynamically generated on save, you can optionally make the field readonly:

// Set a field to read only
function make_field_readonly_onload($field) {
  $field['readonly'] = 1;
  return $field;
}
add_filter("acf/load_field/name=my_image_url", "make_field_readonly_onload");

Upvotes: 0

Eddie Padin
Eddie Padin

Reputation: 695

Problem is that when using the {{meta:somemetatag}} filter with rev slider, it bypasses the acf helper functions, such as get_field(), that handle the heavy lifting involved when navigating the various types of objects and arrays when using the more complex ACF fields. So the trick to getting those values to display properly in your rev slider is to use the native ACF shortcodes in combination with the revslider {{id}} filter.

For example, if you're attempting to display the return values from an acf select field in a post based Revolution Slider you could try the following:

[acf field="my_acf_field_name" post_id="{{id}}"]

This will output the my_acf_field_name ACF field for the current post being rendered by Revolution Slider.

Upvotes: 3

Related Questions