I have a rating system for our products but there is an issue:
by the code, that will SELECT all comments in commentmeta
table that have rating
as meta_key
. even those who do not have a rate (the user did comment but did not leave a rating for the product).
so I need to SELECT just those comments that the rating
as meta_key is not NULL.
my current code:
$sql = $wpdb->prepare( "
SELECT meta_value
FROM {$wpdb->prefix}commentmeta
INNER JOIN {$wpdb->prefix}comments ON {$wpdb->prefix}commentmetament_id = {$wpdb->prefix}commentsment_ID
WHERE comment_post_ID = %d AND meta_key = 'rating' ", get_the_ID()
);
$results = $wpdb->get_results( $sql );
Thanks for helping me
I have a rating system for our products but there is an issue:
by the code, that will SELECT all comments in commentmeta
table that have rating
as meta_key
. even those who do not have a rate (the user did comment but did not leave a rating for the product).
so I need to SELECT just those comments that the rating
as meta_key is not NULL.
my current code:
$sql = $wpdb->prepare( "
SELECT meta_value
FROM {$wpdb->prefix}commentmeta
INNER JOIN {$wpdb->prefix}comments ON {$wpdb->prefix}commentmetament_id = {$wpdb->prefix}commentsment_ID
WHERE comment_post_ID = %d AND meta_key = 'rating' ", get_the_ID()
);
$results = $wpdb->get_results( $sql );
Thanks for helping me
Share Improve this question edited Aug 8, 2019 at 11:31 Sh.Dehnavi asked Aug 8, 2019 at 11:05 Sh.DehnaviSh.Dehnavi 1093 silver badges18 bronze badges1 Answer
Reset to default 0I founded myself my searching:
$sql = $wpdb->prepare( "
SELECT meta_value
FROM {$wpdb->prefix}commentmeta
INNER JOIN {$wpdb->prefix}comments ON {$wpdb->prefix}commentmetament_id = {$wpdb->prefix}commentsment_ID
WHERE comment_post_ID = %d AND meta_key = 'rating' AND meta_value IS NOT NULL AND meta_value <> '' ", get_the_ID()
);
$results = $wpdb->get_results( $sql );
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745258763a4619112.html
评论列表(0条)