Support

Account

Home Forums General Issues get_field and do_shortcode problems

Solved

get_field and do_shortcode problems

  • I’ve been trying unsuccessfully to run a shortcode that I’ve pasted into an ACF field on a page.

    I grab the shortcode like this:
    $slider = get_field('page_slider',$page->ID);
    If I echo $slider, the shortcode prints to the page, but if I put it inside do_shortcode, nothing happens:

    echo do_shortcode($slider);

    if I pass the shortcode directly, as below, it works just fine:
    echo do_shortcode('[slider id="34" name="Main Slider" size="full"]');

    I’ve checked to make sure $slider is a string, I’ve tried stripping out whitespace from front and back. I’ve tried comparing the known string to the $slider variable, and it returns as unequal.

    If I print the known string and the result from get_field out side by side, they look exactly the same.

    I finally gave up and used WordPress’ native get_post_meta, which works fine, but does anyone have any idea why when I run it via ACF’s function it isn’t happy?

  • have you same problem (shortcode that did not work) with Contact Form 7 or some other plugin that use shortcode?
    because i cant confirm any problem with ACF and shortcode. (not inside wysiwyg, nor inside textarea or textbox)

    if you have same problem with Contact Form 7 too, then problem is maybe a filter, your template, or an other plugin that you use.

    if Contact Form 7 has not the same problem then your slider-plugin/shortcode is the problem.

    or maybe this help:
    $slider = get_field('page_slider',$page->ID, false);

  • Your suggestion works like a champ. I’m not sure what “whether or not to format the value” means, but that was what was hanging it up.

    Thanks.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘get_field and do_shortcode problems’ is closed to new replies.