• Shizart

    (@shizart)


    I have a need to find the category id of a post and then use that to display a gallery using shortcode. The plugin author only has shortcode so I have to use that. I have the id I need by using
    <?php $firstCategory = $categories[2]->term_id; echo $firstCategory; ?> Which returns a number for the category.

    I need to get that into my shortcode like:
    <?php echo do_shortcode( '[post-slides cat_id=$firstCategory]' ); ?>
    I don’t know how to write it though. In Javascript it would be something like id=” + firtCategory +”….

    Help! ??

Viewing 1 replies (of 1 total)
  • catacaustic

    (@catacaustic)

    You are almost there. ??

    <?php echo do_shortcode( '[post-slides cat_id=' . $firstCategory . ']' ); ?>

    All that is needed is the extra quotes so that the $firstCategory variable can be outside of the quoted string.

    Just as a note, if you use double-quotes (” instead of ‘) you won’t notice this a sdouble-quotes tell PHP to parse the string for variables where single-quotes tell PHP not to.

Viewing 1 replies (of 1 total)
  • The topic ‘How to write vars into shortcode’ is closed to new replies.