Can't seem to get ACF field to work with Foogallery

526 Views Asked by At

Working with Wordpress now. Struggling with Foogallery and ACF. I have created ACF fields for FooGalleries.

Then, I am trying to call the fields within PHP (namely the code for a static sidebar), with the intention to echo them in a post page where the (Foo)Gallery is showing (in the sidebar).

For context, these 2 ACF fields with a title and a description for each Gallery.

Wordpress does not seem to find the fields. Have tried with do_shortcode(), with get_field(), none works. (get_field returns false):

<?php
$a=get_field('foogallery-title-fr', 868);
echo do_shortcode("[acf field='foogallery-title-fr' post_id='868']");
?>

$a returns false and echo doesn't echo. foogallery-title-fr is the name of the ACF field attached to the (foo)gallery id 868. The ACF fields show without problem on the (foo)gallery page. 868 is also the post ID when I am on the gallery page.

Going nuts and can't find anybody who seems to have tried to do the same...

1

There are 1 best solutions below

6
Daniel Vickers On

After receiving your images it seems you're just trying to use basic ACF functions.

To get an ACF Field:

get_field('foogallery-title-fr');

To display an ACF Field:

the_field('foogallery-title-fr');

To get an ACF Field from another post:

get_field('foogallery-title-fr', 868);

To display an ACF Field from another post:

the_field('foogallery-title-fr', 868);

Here is the information on using fields from different posts: https://www.advancedcustomfields.com/resources/how-to-get-values-from-another-post/

If none of that works try the following:

<?php if(get_field('foogallery-title-fr', $current_foogallery->ID)){
  <?php the_field('foogallery-title-fr', $current_foogallery->ID); ?>
} ?>