If you are going to do this is SQL, use a subquery.
SELECT *,
(SELECT meta_value
FROM wp_commentmeta
WHERE meta_key = 'your-meta-key'
AND wp_commentmeta.comment_id = wp_comments.comment_ID LIMIT 1) as comment_author
FROM wp_comments
Instead of the *
, enumerate the fields you want but leave out comment_author
. Obviously, $wpdb
functions to keep the table names straight.
Related Posts:
- $wpdb->get_results(…) returns empty array despite correct query
- WPDB: how to get the value of a field in a custom database table
- Why is variable not working on custom sql query using wpdb?
- Get Current User Id Inside a Loop Returns 0 For a Shortcode
- Get stock by custom meta field on all Woocommerce variable products
- how to delete 30 day old data using PHP [closed]
- Display fields as values in array from external SQL DB
- Querying wpdb using PHP
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- $wpdb->insert() does not Insert record in a table
- Fatal error: Call to a member function query() on a non-object
- How to retrieve the data from the sever and displaying it in a page?
- Use $wpdb or other PHP script method to find/replace in WP database
- How can I add a new row in a separate database when someone registers via WordPress?
- PHP -> SQL Query with Summing
- How to insert wp_users ->user login name to wp_terms when a new user registering?
- Why my query does not run with prepare
- wpdb getting avatars and author url
- Fetching review value using wpdb class
- WP_Query: How to get results from both meta_key options?
- get_terms with specific id order
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- Passing in MySQL prepare statement parameter separately throwing error
- Database SQL query error
- get different meta-data of a complicated query at the same time
- WordPress SQL Prepare
- Creating multiple tables with Plugin
- can I extend the WP_Query class to deal with ‘duplicate’ posts created by joining to wp_posts?
- WordPress search query, how to modify the sql
- Modify post image in full size
- How to return count of items found in SQL query
- SQL Query Search page
- direct query to post_meta table
- Querying multiple meta_keys in WordPress SQL query
- Changing regular db connection to $wpdb
- Can’t send form data to wpdb when URL has query string
- How to sort search result by post_title, then by post_content
- How to properly prepare a column name if passed to a stored procedure?
- Custom page archive query by url var calling page twice on one of my custom queries?
- Any possible way to make $wpdb->get_results() return anything else than array?
- WordPress custom slug (endpoint) and compare all links
- database interactions using OOP
- How to query for posts with a null or blank post_name?
- WordPress pagination not working with search page
- get current custom post ID by WP_Query method
- Transferring working local PHP site to wordpress – with database (MySQL)
- Echo a hierarchical list of post data from custom fields
- How to securely provide a $_POST var in WP_Query with PHP 7?
- Using foreach loop breaks
- Can’t get wp_insert_post to work
- Trying to establish connection to External Database
- Create WP_Query to search for posts by their categories or their parent/child categories
- WP Query with custom Shortcode
- Getting id of poll from WP database
- How to insert a single row to WP database table?
- wp_query with cat not working
- WSoD being caused by this piece of code
- Advanced Meta Query for Large Calendar Website (12k+ posts) (175k+ wp_postmeta rows)
- How to use an associative array in post__in with WP_Query?
- I want to select the from values from database in WordPress? [closed]
- If Query In Sidebar
- Recent Posts slider, using WP_Query(), loads duplicate sliders
- Compare post-IDs within WP_Query? (Less than / Greater than)
- Importing Geo data into wordpress database
- Detect session/cookie variable in wordpress to prevent access to documents
- $wpdb->update with multiple parameters gives error
- How to use $query->set with post__in?
- Why do WP_Query results change after updating unrelated Advanced Custom Fields (ACF)?
- Loading the same WP_Query in two different wordpress .php templates
- How to prevent WP_Query function from returning all posts when empty?
- Dynamic content based on a URL parameter
- Display a specific category of products in shop page and disable code for specific actions
- Add more button if more 8 items
- How to store post ID’s in cookie or session to display the same posts later
- Update results, Before deleting the related category [closed]
- WordPress, AJAX and pre_get_posts using conditional tags
- Get users that likes the post
- How WordPress reacts to a lack of memory of the server [closed]
- wpdb php get_var query to get ID for URL image doesn’t work for ID over 999
- get_posts() and WP_query limits ‘AND’ conditions to a maximum of 6 for meta value queries in WordPress
- Exclude posts based on meta value
- wp query foreach deleting record returning only first or last item
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Custom query, checking values of multiple meta keys
- Archive post by meta value + 24hours
- auto-populating custom nav with all items from custom post type
- inserting a post from an extern php file but post content doesn’t show on wp site
- Database query works fine outside WordPress
- Using $wpdb (WPDB class) ‘replace’ with multiple WHERE criteria problem
- Remove echo from shortcode
- Genesis framework comments broken?
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
- Databases – Submitting data from inputs to database [closed]
- Help with a $wpdb MySQL Query
- WordPress theme options error
- Security for data obtained from the database
- Get posts from multiple post type
- How to pass orderby params to $wpdb->prepare()?
- Is it possible to retrieve all posts with a certain value for metadata?
- How to get all author posts outside of author templates