0

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...

Ryan Schaefer
  • 3,047
  • 1
  • 26
  • 46
Eric
  • 243
  • 3
  • 9
  • Is the field inside a repeater at all? Or inside a flexible content field? If it's in the repeater use get_sub_field and if it's inside flexible content field tell me and I will write an answer. – Daniel Vickers Apr 25 '18 at 09:13
  • Many thanks. Will have to do a bit of research, you are way ahead of me. Will let you know the answers tormorrow! – Eric Apr 25 '18 at 20:50
  • So I will venture an answer. What I read is that repeater and flexible content fields are features of ACF Pro. I am still with the free version, so I guess it means I use neither. – Eric Apr 25 '18 at 20:53
  • So I will venture an answer. What I read is that repeater and flexible content fields are features of ACF Pro. I am still with the free version, so I guess it means I use neither. What I did was simply to create a field in the ACF admin menu. Then below the management panel, there is a zone titled "Assign this group of fields", and then a line with 3 drop-downs under the head "show this field when". The dropdowns' default options are "type of publication", "equals" and "post". That last dropdown has an option "foogallery". – Eric Apr 25 '18 at 21:02
  • Selecting that option, the field then appears in the page where I can create a new foogallery, to be filled. That I did, and nothing more. Then I added the various versions of the shortcode functions in the PHP of my static sidebar, and voilà. Was expecting it to work but did not... E. – Eric Apr 25 '18 at 21:02

1 Answers1

0

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); ?>
} ?>
Daniel Vickers
  • 1,054
  • 1
  • 12
  • 32
  • Well, the test (get_field('foogallery-title-fr', 868) == 'foogallery') returns false and the code is skipped. Took two screenshots and posted them here: https://www.dropbox.com/sh/w7l83tkxp6rpwg1/AADx5NAih3uAX4N_I3Gm3VhGa?dl=0 – Eric Apr 26 '18 at 15:51
  • Updated answer, try using the_field(); – Daniel Vickers Apr 26 '18 at 16:06
  • Many thanks! Will let you know when I get it to work! – Eric Apr 27 '18 at 08:51
  • OK! Seems to be a bug with one element or another. Probably ACF. I got it to work for 5 minutes using the_field. The added a block of code to the sidebar (a test on the langage to select between titles) and it stopped working. Returned to the code version that was working, and now doesn't work anymore... Many thanks anyway, you clarified the use of the_field in my mind, and got me going again! E. – Eric Apr 27 '18 at 09:38
  • Seems to be the case. When one changes the names of the ACF fields, the records in the Gallery record in the metapost DB seem to get messed up. If one gets back to clean version of the DB, then recreates the fields and avoids changing the names, it works. E. – Eric Apr 27 '18 at 10:33
  • Awesome, glad I could help. Hopefully you can clean up the DB and get it working :D – Daniel Vickers Apr 27 '18 at 11:06