You have to use JOIN
for that. Try it like this:
$wpdb->get_results("SELECT tags.*, $wpdb->posts.*, $wpdb->postmeta.*
FROM tags
INNER JOIN $wpdb->posts ON tags.charity_id = $wpdb->posts.ID
INNER JOIN $wpdb->postmeta ON tags.charity_id = $wpdb->postmeta.post_id
WHERE tags.charity_id = $charity_id"
);
Related Posts:
- Grouping related postmeta data via SQL query
- mySQL query. ORDER BY meta_key
- simple sql query on wp_postmeta very slow
- How many WordPress SQL Queries per page?
- Search custom post type by meta data
- Multipart/formatted MySQL query problem
- How to display liked posts of current user in wordpress?
- Filter query posts by the count of metas for a meta key
- Are database queries created using WordPress filters protected from SQL injection?
- Save default value for empty or missing post meta
- Mysql / WordPress killing my server with 80k users [closed]
- Slow meta_query with about 4 milion record on wp_postmeta
- Select User by Joining Multiple Meta Value Results
- Remove posts from query for events whose start date has passed
- Update slug (URL) of pending posts via phpMyAdmin
- My SQL function to change user_name
- Query metas (and not : query posts by metas)
- You have an error in your SQL syntax – Help with query
- MySQL variable in query
- how would I create a custom query to get all users, and a related post based on a postmeta field?
- Help with MySQL to $WPDB query
- SQL query to select posts from multiple categories
- How do I see the mysql query generated by get_posts( $args )?
- Alter query with posts_clauses to retrieve NULL values last
- Issue with using add_rewrite_rule() for post querying custom fields
- MySql Query very slow
- Searching With Apostrophe
- WordPress Query wp-terms SLOW
- Query posts according to specific post meta values
- wpdb COALESCE won’t work
- Order by meta value pro first then meta value free in my search function
- Get posts from category with custom query
- how to insert missing tags into the posts through mySQL?
- Ideas how to search & replace post_content when string contains a newline?
- Valid SQL query return empty
- mysql query – how to escape apostrophe?
- Query the WordPress database to get data together with replaced information
- Optimize slow SQL query for multiple meta values
- Updating with $qpdb->query() always returns 0 rows affected
- get_post_meta with WP_query
- Declaring a var, placing it in a query and using the output of the query?
- How to return count of custom post type posts with a specific custom field value via $wpdb?
- WordPress Mysql query and Duplicate
- Help with Related Posts Function
- Combining two meta_values within one row with query
- How to delete all images from code in all post_content
- I want to get on those users their meta value are like “AGENT” .. but this query is not working
- Displaying data from custom table
- Get 2 meta values from meta key column
- PHP Fatal error: Uncaught Error: Call to a member function insert() on null
- SQL query to delete users with multiple meta keys and comments
- Is there any way to get all custom posts and all custom terms with it’s meta in few queries?
- Sort by postmeta on when searching
- OR condition not working
- Trouble migrating custom post types from non-wordpress cms
- Are there any best practices for creating a Like/Favourite feature in WordPress using custom MySQL tables and without any plugins?
- Performance of wp_get_attachment_image_srcset() and wp_get_attachment_image_url()
- How to make MySQL search queries with quotes
- how to get postmeta info based on multiple categories?
- Use $wpdb->get_results with filter based on array
- What is the best way to query posts based on live data?
- Mysql query and odd results
- sql for querying post and their category
- Access Tables with number prefix
- Get Terms by IDs with IDs order
- Slow wp_enqueue_media()
- Custom Queries: Joining On Meta Values From Two Custom Post Types
- WordPress Find Duplicate Post By Content
- WP Query Sort by meta value (date)
- Disable the MySQL query in the main query
- How can I get the query that would be run for the archive page?
- Select query for a login
- What’s wrong with my $wpdb prepare?
- INSERT ON DUPLICATE KEY UPDATE failes in postmeta table
- wpdb print all post meta
- Export Specific User data without plugin
- How to write: $wpdb->update having WHERE NOT value pair in the array
- Inner join overrides Advanced Custom Fields plugin’s get_field [closed]
- Query does not return content
- Custom SELECT Query With Multiple Meta Values (Ordering Problem)
- Query posts dynamic date range
- Parse query filter in wordpress and relation
- get last post’s link with SQL query
- List WordPress Post and Related Attachments outside of a post page
- Excluding posts by meta, and also keeping posts without the meta
- Problem on displaying the results on my query
- SQL query – get a featured image’s alt / alternative text
- Improve performance of slow query
- WordPress search in modified post title
- Insert, update or remove data from database (usermeta)
- I need query_posts() to order results first by a meta value and then by post ID
- Archive query not working correctly
- Set posts per page for parent category and it’s all children
- Exclude sticky posts from query
- Adding an orderby filter, casting postmeta with multiple keys
- How to query different categories on index?
- How to specify what kind of is_single post?
- Print data from wordpress sql query
- Can I create my own query in wordpress with traditional methods?
- How to show sticky posts on all pages of the pagination, not just the first page?