D
D
Diana2020-08-23 01:37:36
WordPress
Diana, 2020-08-23 01:37:36

How to send sql query using PHP?

Dear programmers, tell me, please!

There is a food blog on WordPress. Installed plugin Yet Another Stars Rating. I want to pull out the digital values ​​​​of the rating of records in order to add microdata. There are plans to remove the micro-markup of the plugin. Why? The Blog has already set up its own markup of recipes through functions and meta tags. After installation of a plug-in in a DB there was a trace.
wp_yasr_log table

The following 2 queries in the database give the desired values
​​SELECT AVG(`vote`) FROM wp_yasr_log WHERE `post_id` = 53
SELECT COUNT(`vote`) FROM wp_yasr_log WHERE `post_id` = 53

53 - record ID, must be current.

How to correctly execute these queries in the DB and get the values ​​(quantitative) inside the template

Tried that, didn't get anything. More precisely, I get 0.

<?php 
global $wpdb;
$post_id_num = get_the_ID();				
$rating_count = intval(
$wpdb->get_var( "SELECT COUNT(`vote`) FROM $wpdb->yasr_log WHERE `post_id` = $post_id_num" 
         ));
?>

<meta itemprop="ratingCount" content="<?php echo $rating_count; ?>">


Below is a screenshot of the wp_yasr_log table from the database
5f419ff77be38029624330.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question