Insert variable value inside shortcode

I want to use the shortcode below to add a review box to posts in my wordpress template:

<?php echo do_shortcode('[rwp-review id="X"]'); ?>

Where X is the Review ID of the review box for each post.

To get the Review ID, I have the code below but it is not working. $postid gets the current post ID. $box result returns array values for the review box one of which is the Review ID. If I echo $reviewid, I get the Review ID which can be 0, 1, 2, 3 and upwards.
I then tried to use $reviewid in the final shortcode but It is not working. I have very little PHP knowledge so I think I inserted the code the wrong way.

<?php
        $postid = get_the_ID();
        $box = RWP_API::get_post_reviews_boxes( $postid, false );
        $reviewid = $box[0]['review_id'];

    ?>

    <?php echo do_shortcode('[rwp-review id=". $reviewid . "]'); ?>

Can anyone suggest the best approach to this?

Read more here: Insert variable value inside shortcode

Leave a Reply

Your email address will not be published. Required fields are marked *