How can I display acf metadata array in revolution slider - php

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

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.

Related

Display ACF custom fields on WooCommerce store home and category listing

I am trying to display Advanced Custom Field on my WooCommerce storefront in html list tag. I modified the file:
content-product_cat.php
from this:
<li <?php wc_product_cat_class( '', $category ); ?>>
to this:
<li style="background: <?php the_field('my_ACF_field'); ?>" <?php wc_product_cat_class( '', $category ); ?>>
And also I added ACF field on my WP backend and assigned it to my page called "Store" which is the WooCommerce storefront. I can fill the input on my backend (Store page) but it's not showing on storefront/category page, it's just not passing. Where is the problem?
I also tried to set this field as taxonomy, and display it on category setting in WooCommerce, also without success.
I think you'll need to use the second parameter on ACF the_field, to get the value for the specific object that you're after. E.g. if you have the ACF Field set on a product category, you'll need to pass in the term that you're currently looking at to get the right value.
I believe that on a category page you'll need to use something like
<li style="background: <?php the_field('my_ACF_field', $category);?>" <?php wc_product_cat_class( '', $category ); ?>>
This ACF documentation field gives more detail about adding fields to taxonomy terms: https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/

Display image after taxonomy text with advanced custom fields

I have created a custom post type called:'activities' and created a taxonomy for it called: 'activity_locations'. I have then added a custom field to the taxonomy for an image using Advanced Custom Fields, this image field is called: 'activity_location_image'
On the single template I have managed to display the taxonomy for the product with the following code:
Available in: <?php the_terms( $post->ID, 'activity_locations', ' ', ' / ' ); ?>
However I need to elaborate on this to add a small image after the taxonomy text. I have tried the following code but it hasn’t worked (nothing is displaying):
<?php
$term = get_field('test');
if( $term ): ?>
<img src="<?php echo get_field('activity_location_image', $term); ?>" />
<?php endif; ?>
Can anyone offer any advice/assistance on how to make this work?
If you are still on the single template page, then get_field() without a second argument will only be fetching metadata for your current post object, not the related term objects.
If you read the documentation for get_field() you'll see that to query for term fields you need to use the format
get_field('field_name', 'taxonomyname_X)
Where taxonomyname would be activity_locations and X would be the term ID.
Since you want to customize the display and use the data about the terms, you'll have to swap the_terms() with wp_get_post_terms() which will give you an array of term objects. You can then loop over the array, grabbing the image for each term and outputting the HTML to display the term.

ACF fields not showing on a wordpress custom taxonomy page

I'm having trouble showing ACF on a custom taxonomy page.
The custom tax is 'destinations' with the page being taxomony-destinations.php the field is called 'destination_landing_image. I'm trying to display it on 'mysite.com/destinations/coutryname' as follows:
<?php if (have_posts()) : while (have_posts()) : the_post();
$destination_landing_image = get_field('destination_landing_image');
<img src="<?php echo $destination_landing_image['url'] ?>" alt="<?php echo $destination_landing_image['alt'] ?>">
<?php endwhile; endif; ?>
Oddly enough the page in question does show up the ACF fields within the custom post type(holidays) which is lower in the page. So I guess firstly am I calling it correctly within the loop? and Secondly is a custom taxonomy the right type of page to use?
When you use ACF with posts you can just use get_field() as you are, but when you use it with anything else such as taxonomies, users or options, you need to give ACF a hint about how to look it up. In this case you need to tell it what taxonomy and term you are specifically targeting. Luckily both WordPress and ACF make this really easy:
//Ask WordPress for the currently queried object
//http://codex.wordpress.org/Function_Reference/get_queried_object
$obj = get_queried_object();
//Pass that object as a second parameter into get_field
$destination_landing_image = get_field( 'destination_landing_image', $obj );

How can I use a [Shortcode] in my custom field wordpress

I have a custom wordpress post.php, all posts within a specific category will use this template. In nearly every post there will be scrolling testimonials, to handle this I am using a layer slider.
Within the page I have a custom field of testimonial that is filled with something like [layreslider id="2"]
In my php file I have:
<div class="trips-testimonials">
<?php do_shortcode(get_post_meta($post->ID, 'testimonial', true)); ?>
</div>
This seems to do nothing. If I add echo to the PHP:
<?php echo do_shortcode(get_post_meta($post-ID, 'testimonial', true)); ?>
I get the output of [layreslider id="2"]
Here is a sample page, the blue box under the photo is where the slider should show up.
http://www.ct-social.com/ctsdev/aff/capri/
Thank you very much for your help.
looks like you miss the > from post Id so it should read
<?php do_shortcode(get_post_meta($post->ID, 'testimonial', true)); ?>
Also you may need to call global $post; if outside the loop.

Wordpress display page contents and a loop?

I have a custom loop in a page template to display posts by category by give category and tag. It works, but above the loop I need to show the content of the page itself, i.e. the content that's been entered into the Wordpress Dashboard normally.
What do I add to my template to display this content?
I have tried:
$id = $post->ID;
get_page($id);
// then my custom loop
Which does get the current page ID, but no content.
In WordPress, calling
<?php the_content(); ?>
will pull in the content from the WYSIWYG editor on the page that is using that template as long as it is inside the loop.
The most basic example of this might look like this:
<?php while (have_posts()) : the_post();/* Start loop */ ?>
<?php the_content(); ?>
<?php endwhile; /* End loop */ ?>
<!-- Enter your custom loop for displaying posts by category down here -->
More info here: http://codex.wordpress.org/Function_Reference/the_content
In my case, with a modern theme and using Gutenberg blocks, I had to apply filters to the content before the posts loop, as mentioned in this thread here: Proper way to get page content
Following one of the examples, a simple working solution would be:
<?php
$id = 669; // page ID that has been assigned for posts
$post = get_post($id);
$content = apply_filters('the_content', $post->post_content);
echo $content;
?>
<!-- Enter your custom loop for displaying posts by category down here -->
To display the content of the page, using the the_content() function.
Added your custom loop after this function call.

Categories