How to JOIN tables with $wpdb
-
I want to JOIN $wpdb->comments with commentmeta. Im only trying to get the field “meta_value”.
global $wpdb; $commentQ = "SELECT * FROM $wpdb->comments " . $whereClause . $orderBy; $comments = $wpdb->get_results( $commentQ, ARRAY_A); // build the string $commentString = ""; $count = 0; if( $comments ){ $first = true; foreach( $comments as $row ){ if( $first ){ // column labels foreach ( $row as $col => $value ){ //$commentString .= $col . chr( 9 );
After i join the tables i want to get “meta_value” from wp_commentmeta_88 and insert it instead of “comment_author”
// Column Author if($col == 'comment_author') { $commentString .= 'User Meta '; } // Column IP if($col == 'comment_author_IP') { $commentString .= ' IP '; } // Column date if($col == 'comment_date') { $commentString .= ' Datum '; } // Column comment if($col == 'comment_content') { $commentString .= ' Meddelande '; } } $commentString .= chr( 13 ); $first = false; }
[please remember to mark any posted code – https://codex.www.ads-software.com/Forum_Welcome#Posting_Code ]
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘How to JOIN tables with $wpdb’ is closed to new replies.