Pass ACF value into a shortcode

How do I pass an ACF value into a shortcode for a different plugin/function?

I’m building out a booking site with need to add a calendar. The calendars reference an ID (number) that is contained in an ACF field.

Shortcode needs to look like this: [bookingcalendar type=“ID”]. I need to be able to dynamically replace ID with the number specified in the custom field of each post.

What’s the best way to achieve this?

I wanted to return to this in case anyone else might have had a similar query.
The Dynamic Inserter function solves this rather easily as it turns out.

In my case, all I needed was to insert an ACF into a shortcode. Since Cwicly’s Paragraph block is a bit of a jack-of-all-trades block, it’s all we need.

First, we create the ACF field as needed and grab the slug:

Next create the post and enter the value for this field:

Finally, add the shortcode using a paragraph block and the Dynamic Inserter Function to place the field value in the code.
In my case, the code needed to be [bookingcalendar type={RESOURCEID} nummonths=2]:

The ACF field slug needs to be entered manually, which we would have grabbed from the Field Group edit page earlier:

From here, just complete the rest of the shortcode, and that’s it.
image

1 Like