• Resolved maximdesign

    (@maximdesign)


    Hello,
    I wonder if I can put an ACF shortcode.
    I’m trying to target a specific class declared in the post.

    What do you think about?
    I tried but it didn’t work.

    Screenshot:
    https://snag.gy/APHalq.jpg

Viewing 12 replies - 1 through 12 (of 12 total)
  • panosru

    (@panosru)

    Seems like you can’t use a shortcode as a value inside a VC element, you can only use it inside textarea.

    Also from what I understand this plugin just enhances the already existing functionality of ACF inside VC, it just allows you to render google maps for instance and others custom ACF fields, nothing besides that.

    It’s a pity as I was expected to be used in the way you try to use it.

    panosru

    (@panosru)

    @maximdesign,

    I created this filter in order to archive my needs:

    add_filter(‘the_content’, ‘apply_acf_shortcodes_to_content’);
    function apply_acf_shortcodes_to_content ($content) {
    // Check if “{acf” appears in text
    if (false !== strpos($content, ‘{acf’)) {
    // Find converted ACF shortcodes and bring them back to normal
    preg_match_all(‘/{[^{]*acf[^}]*}/i’, $content, $matches);

    // Set to current
    $evaluated = $matches = current($matches);

    // Loop through matched shortcodes
    foreach ($evaluated as &$value) {
    $value = do_shortcode(str_replace(
    array (‘{‘, ‘}‘, ‘‘),
    array ( ‘[‘, ‘]’, ‘”‘),
    $value
    ));
    }

    // Replace matched with values
    $content = str_replace( $matches, $evaluated, $content );
    }

    return do_shortcode($content);
    }

    Put it inside your theme’s functions.php file

    • This reply was modified 8 years ago by panosru.
    panosru

    (@panosru)

    you can find the code here: https://pastebin.com/46y2VYRk

    I haven’t tested it from performance perspective

    • This reply was modified 8 years ago by panosru.
    panosru

    (@panosru)

    Update to the regexp due to an issue: https://pastebin.com/v3k5KNyW

    Thread Starter maximdesign

    (@maximdesign)

    Hello @panosru,
    thanks for your help.

    Unfortunately, it doesn’t seem to work: it continues to display the shortcode as a class, instead the value.

    panosru

    (@panosru)

    @maximdesign,

    strange as I use it for me and it works like a charm, I actually extended it a bit more to work with repeater field and integrated it with vc and templatera, take a look at the code here: https://gist.github.com/panosru/f2d3d6f5008958ae81b71510800be108

    Plugin Author K?re Mulvad Steffensen

    (@dejliglama)

    HI guys, Let me understand this correctly. You want to put a custom field value into a field in an VC element – in this case our plugin, and the class field ?

    So we would have to render any afc shorcode in that field ?

    Thread Starter maximdesign

    (@maximdesign)

    Hi,

    I’m trying to explain what we want achieve.

    Each post has a custom field, let’s say “color”.

    Then, there is the VC grid builder.
    In particular, there is a field for the class.

    We want to render the custom class associated in the post.

    panosru

    (@panosru)

    I’m actually using this code: https://gist.github.com/panosru/f2d3d6f5008958ae81b71510800be108 in order to use acf values inside VC elements and templatera, @dejliglama in case you find any use of the code feel free to use it

    Plugin Author K?re Mulvad Steffensen

    (@dejliglama)

    Thanks @panosru we will look into that!

    Plugin Author K?re Mulvad Steffensen

    (@dejliglama)

    Hi @maximdesign – The shortcode inside the VC element field wont work. It’s a shortcode inside a shortcode, which we do not handle at this time. Not even sure it’s something we can handle without also having VC to handle it. Since all of VC is basically shortcodes.

    @panosru could you give me a hint what to do with your code, please?

    • This reply was modified 7 years, 8 months ago by wwwland.
Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘ACF inside visual composer Grid Builder’ is closed to new replies.