php - Query database with comment meta -


i have wordpress comment box 2 custom files, name , country, written database meta_key tag comment_name , comment_country. need display these comments needs include actual comment, values of 2 custom fields. need query database need retrieve comments, not comments particular page.

the code (kind of) have is:

<?php  global $wpdb; $querystr = " select comment_content $wpdb->comments inner join $wpdb->commentmeta on meta_key = 'comment_name'"; $comment_info =  $wpdb->get_results($querystr, object); echo '<ul>'; // display results foreach($comment_info $info) {  echo '<li class="commentbox"><p>'. $info->comment_content .'</p><h6>'. $info->meta_value .'</h6></li>';  } echo '</ul>';                             ?> 

as can see, need comment_content field in wp_comments, combine meta_value of 2 meta_keys. haven't figured out how try , add second meta_key/value code.

can me please @ wits end this!

update: can query info need. had use aliases can query 2 different meta_keys corresponding values. code:

$querystr =  " select * $wpdb->comments, $wpdb->commentmeta commentmeta1, $wpdb->commentmeta commentmeta2  $wpdb->comments.comment_id = commentmeta1.comment_id  , $wpdb->comments.comment_id = commentmeta2.comment_id  , commentmeta1.meta_key = 'comment_name'  , commentmeta2.meta_key = 'comment_country'  order $wpdb->comments.comment_date desc";  $comment_info =  $wpdb->get_results($querystr, object); 

so need reference commentmeta1 , commentmeta2 in loop output 2 different values. code using:

echo '<ul>'; // display results foreach($comment_info $info) {  echo '<li class="commentbox"><p>' . $info->comment_content . '</p><h6>' . $info->meta_value['commentmeta1'] . ', ' . $info->meta_value['commentmeta2'] . '</h6></li>';  } echo '</ul>'; 

the meta values don't output should, takes first letter of commentmeta2 ('comment_country'), , duplicates each instance (pic below). if query 1 meta key can display value in loop fine running $info->meta_value. how can meta_values per query?

img of current output

how specifying columns need in select statement:

select comment_content, comment_name, comment_country ... 

then reference them in html $info->comment_name , on.

if need more direction, need share database schemas comments tables.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -