Get ACF fields from options

Hello Guys!

I was using your older plugin “Custom Content Shortcode” which in my opinion I thought was simpler. We had built several websites with this. Excellent work.

Now, with this plugin we have some questions but we will start with our first question

We have a group through ACF and some fields such as title, image, link etc

We have displayed these fields in an “options page” that we created.

I want to make a template for this, but to be able to understand this new version of the plugin, how could I do that?

For now,
Thanks in advance

Hello, thank you for the feedback. Welcome to Loops & Logic and the forum.

It’s true that CCS was a simpler plugin, easier to use with shortcodes. What happened was, I was creating more complex and bigger websites using CCS, and began to have difficulties due to the limitations of how shortcodes work, its syntax and parser (in WP core).

For example, the post content has many filters applied for automatic formatting, including the do_shortcode function; this causes unexpected changes to the resulting HTML. Another issue was that shortcodes aren’t really designed to be used in a “tree structure” like HTML templates. They can’t be nested, cannot pass values to each other, don’t work well in HTML attributes, and so on.

L&L was created to freshly imagine a template language that’s seamlessly integrated with HTML. It solves the issues I had with shortcodes, and made the templates more extensible and scalable. But I agree it’s not as simple to get started as with CCS. We’re trying to improve it with better documentation, examples, and articles.


About ACF integration, there’s a documentation page listing the supported field types.

At the bottom of the page is a short explanation of how to get fields from an options page. Assuming the options page was added with the acf_add_options_page function, you can access its fields by adding from=options to the Loop and Field tags.

Here is an example of getting child fields from an ACF group field.

<Loop acf_group=field_name from=options>

  <Field title />

  <Loop acf_image=image_field_name>
    <a href="{Field url}"><Field title /></a>
  </Loop>
</Loop>
1 Like

Hello Eliot and thank you for the understand!

Yes it is true it is more complicated. I hope it can become more easy to use and friendly as the previous one.

I tried your code but it does not work

Let me tell you all the steps I took:

  1. I have create a template with your code.

  2. Change this => acf_group=field_name - with the name of the group that acf gives me

and change this => acf_image=image_field_name - with the name and field that I have created and exists within the group.

  1. I try to add it via shortcode, as [template id=450] in a page, but not working :frowning:

Maybe we can try a simple field type first, like a text field from the options page.

<Field text_field from=options />

If you could add the text field and enter some value in the options page - does the above code show the field value as expected?

Then we can test with a text field inside a group field.

<Loop acf_group=field_name from=options>
  <Field text_field />
</Loop>

Does the above code display the text field value?

And finally, an image field inside a group field.

<Loop acf_group=field_name from=options>
  <Loop acf_image=image_field_name>
    <Field url />
  </Loop>
</Loop>

Well,

This/First field not working

<Field text_field from=options />

This field: Yes, is working. The title appeared

<Loop acf_group=field_name from=options>
  <Field text_field />
</Loop>

Also: this working.

<Loop acf_group=field_name from=options>
  <Loop acf_image=image_field_name>
    <Field url />
  </Loop>
</Loop>

The image that returns we try to bring it without a link, but without luck.

I found the way for the image… nevertheless, it is quite complicated I would say although it is recognized from what I understand and at least I am happy about it.

I will continue with my work and if I need any further help, I will definitely go through here :slightly_smiling_face:

Hey @darkmesaia, welcome to the forum!

Since you’re just starting the process of learning to write L&L markup, you might find this beginner’s guide useful in helping you get a good mental model of what L&L can do and understand why some of the markup you tried above does or doesn’t work on your site. Once you’ve got a good understanding of how it works, this post about L&L syntax and terminology might make it easier to read through the documentation and start writing your own markup. Hope those are helpful resources! If ever anything is unclear, please do reach out here or in the comments on those posts. I’d love to hear how those posts could be improved to help people like you get the most out of L&L.

Best of luck with L&L! :smile:

2 Likes