Support

Account

Home Forums General Issues Using field data in shortcode

Solving

Using field data in shortcode

  • I’m sorry that this isn’t an “issue”, but I’m having trouble understanding basic PHP logic in regards to your plugin.

    I’m using wordpress’ do_shortcode in my template to insert a shortcode from another plugin. The shortcode requires a variable that I’m setting with my custom field, i.e. id=”ID-CODE”. Since it’s a string within a PHP command I can’t just begin another command, but I am aware I can call the content of the post’s custom field in another way.

    Thank you for your time.

  • Hey @tintin,

    You’ll want to create a variable for your string then use a concatenated string -> http://php.net/manual/en/language.operators.string.php.

    $idcode = get_field('id_code');
    echo do_shortcode('[shortcode id="'.$idcode.'"]');

    You could also skip the variable all together and just use the get_field function inline.

    echo do_shortcode('[shortcode id="'.get_field('id_code').'"]');

    Hope that helps. 🙂

    EDIT: Added inline function option.

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

You must be logged in to reply to this topic.