Calling plugins API within a theme

Damn it, I even figured it out and it works.

So, I added this directly into my listing template, nothing was added into functions.php nor was any other file altered. I first called the $post variable – in the WordPress documentation it says it “contains data from the current post in The Loop.” I figured this will work as the code has to be in the loop and added it to the top.

As said in the documentation “You must pass a valid post id to the method to get the correct data” I thought to myself well, I somehow need to get that post ID before everything is executed. Therefore the $id string, which gets the WordPress post ID.

The second part, from if ( class... to the last part $id ); is from the plugin API documentation, and it calls only the final score of the review, without any design.

But heck, this didn’t show the review yet. I heard once “echo” does miracles, as it calls out the function and it shows it. So I said – why not? By WordPress documentation echo outputs one or more strings.

And voilá – it works. I learned a lot of new things by combining different sources and it took me 3 days to figure everything out. Now it’s great I know how to output this without messing with a lot of files and – it’s simple.

Hope it helps someone like it did to me 🙂

<?php
$post = $wp_query->post;
$id = get_the_ID();
if ( class_exists( 'Lets_Review_API' ) ) {
$lets_review_api = new Lets_Review_API();
$lets_review_final_score = $lets_review_api->lets_review_get_final_score( $id );
echo $lets_review_final_score;
}
?>