• Resolved corrinarusso

    (@corrinarusso)


    Hi guys,

    I’ve tried this every single way I can think of – I can’t pass in a variable from Advanced Custom Fields into this shortcode.
    The ACF is a URL string to a PDF document.
    The shortcode which is from a plugin works fine on its own – it “embeds” the PDF into the page.

    But – I can’t pass the URL string into here – any ideas ????

    This does not work :

    $urlis = the_field('candidate_document');
    $shortcode = sprintf (
            '[pdf-embedder url="%1$s" toolbar="both" toolbarfixed="on" scrolltotop="on"]',
            $urlis );
    echo do_shortcode( $shortcode );

    and this does not work :
    echo do_shortcode( '[pdf-embedder url="' . the_field(candidate_document) . '" toolbar="both" toolbarfixed="on" scrolltotop="on"]' );

    I have verified that the URL output is correct – it displays the URL to the PDF.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Joy

    (@joyously)

    Does the_field() echo its result, like WP functions that start with the_?
    Why build a shortcode when you can call the handler directly?

    Thread Starter corrinarusso

    (@corrinarusso)

    For anyone trying to retrieve data from a post field using Advanced Custom Fields, and then you need to create a new custom post template type and then you need to output a variable from one of the fields into a shortcode – you need to use ***get_field()*** – NOT the_field.

    Arrrrrrgh. 3 hours of my life on three letters.
    This works :

    $urlis = get_field('candidate_document');
    $shortcode = sprintf (
            '[pdf-embedder url="%1$s" toolbar="both" toolbarfixed="on" scrolltotop="on"]',
            $urlis );
    echo do_shortcode( $shortcode );
    Thread Starter corrinarusso

    (@corrinarusso)

    It *does* @joyously – thank you for the reply. 🙂
    I was grasping all afternoon which is why I put it into a variable – get_field, not the_field.
    Ugh.

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

The topic ‘Templates + Shortcodes + Variables’ is closed to new replies.