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
- Can i use php sql functions instead of $wpdb?
- wpdb::prepare was called incorrectly
- Custom query to get post names beginning with a digit
- count number of user comments with a specific comment meta value
- PHP syntax error when using wpdb update?
- Duplicates with WP_Query loop
- my function doesn’t return my post from today
- “The plugin generated 2694 characters of unexpected output…” on Plugin activation, CREATE TABLE sql command not working
- Use wp_get_recent_posts with search term
- have_posts() execution failure
- Can’t search posts using WP_QUERY inside AJAX Function
- How can I use wp_query to show all product data using just the products ID?
- WordPress pagination not working with search page
- Getting id of poll from WP database
- Advanced Meta Query for Large Calendar Website (12k+ posts) (175k+ wp_postmeta rows)
- I want to select the from values from database in WordPress? [closed]
- Detect session/cookie variable in wordpress to prevent access to documents
- How to store post ID’s in cookie or session to display the same posts later
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- auto-populating custom nav with all items from custom post type
- WordPress theme options error
- Get posts from multiple post type
- WP_Query fails despite having 1 post
- Custom array from a query only write the last row of the query
- Querying Database with wpdb
- the_posts_pagination() not working in wpquery
- WP_Query: getting posts where custom field exists
- Custom route and query
- Getting posts to exclude from array
- Custom post type permalinks do not appear using the link functions
- array_rand not working correctly?
- WP_Query() load selected post
- How to extract information from a wp_query result?
- mySQL queries are executed twice on wordpress website
- Remove password protection from all posts
- Modifying WP URL handing code?
- Free search and custom taxonomy query not providing the same result
- How do I reset $wp_query in a function?
- Replace a single variable with add_filter
- Nested Queries of decreasing specificity
- Wrong pagination results, page counter resets when navigating
- Sending simple variable on single page to WP JSON
- How to exclude meta no index pages from wp_list_pages
- meta_query search names when they have middle initials
- What is the correct way to search 3 custom fields only in WordPress?
- get_filtered_term_product_counts – Get product terms if any products
- List all ACF field values across every post on one page
- Multiple Arrays for Custom Post Query using Boostrap accordions and ACF repeater fields
- Query to show average # of months all accounts with specific role have been active
- Query doesn’t display text data with apostrophes
- Getting error in sql query
- Querying posts from wordpress with 2 or more conditionals
- Display Year and Month from custom field + Age Calculator
- insert thumbnail image from php script
- Accessing external database: ERR_INCOMPLETE_CHUNKED_ENCODING
- Masonry layout within the loop
- Get null from POST
- How to export database correctly for local to online
- wp_query on search results page showing all results every time
- Insert into db with foreach problem
- Putting form result in my database
- SQL – How to echo out inside of where statement
- How can I update a value of a field depending on outside source?