If you’re trying to get all meta values for a key within a specific post type, you can do something like this in a single query:
SELECT post_id, meta_value FROM $wpdb->postmeta pm, $wpdb->posts p
WHERE meta_key = 'sd_rating' and pm.post_id = p.ID AND p.post_type="cpu"
Related Posts:
- Create a WordPress Database query to find users who purchased specific product through WooCommerce [closed]
- find a random blogid across my multisite network that has at least one post published
- Create Pages from Database
- How do I write this SQL statement for Posts written in last 24 hours?
- Combine tax_query and meta_query in WP_Query
- Want to filter only parent post in admin area
- How to use custom post type APIs, but use a different db table
- Calculating Bayesian average for custom post type
- Order by custom table and multiplication
- Adding custom tables to WordPress
- $wpdb: Counting posts corresponding to 3 terms in 3 different taxonomies
- Insert post metadata for all posts in CPT at once if metadata no existent
- Convert simple SQL Query to WordPress query
- convert custom query to wp_query
- Converting the_content string to an array?
- How to import a custom MySQL DB table into a WordPress custom post type
- WP_Query orderby and tax_query
- Save custom post type to external database
- Proper way to display latest 5 posts grouped by post type?
- WPDB for post count on post
- foreach loop inside the loop creating duplicates in output
- $wpdb is queried but results don’t show
- Does this archive template part look like its making too many calls to the db?
- Custom post type and custom taxonomy key lenght & query performance
- How select query is generated in a Custom Post Type?
- How to store additional data that is related to core data
- How to use costum database table for custom post type
- Populate custom post type/custom fields from an external database
- Custom post order when using OR relation
- CPT or Custom Table for Repository of Serial Numbers
- Use Tags to Query Associated Multiple Posts and Get The Average Of Custom Field Values
- Shared Custom post type between WP network sites
- Assign a tag to custom post type using a query
- Display all posts in a custom post type, grouped by a custom taxonomy
- How to return number of found rows from SELECT query
- Get posts for custom post type with WP_Query
- Custom Post Types, or completely custom?
- WP_Query() show posts that end later than today
- How to check if a WP_Query has data
- Sorting a query by custom field date
- Enforcing canonical URLs with multiple custom post types
- WP_Query -> sort results by relevance (= most tags / taxonomy terms in common)
- Retrieving 3 latest post from each of 5 different custom post types
- how to group custom post type posts by custom taxonomy terms
- How to sort CPT by custom meta value (date), and return posts month by month
- Wp-query causing problems with the_content();
- $wpdb returns no results with SELECT query on custom post type, works on default post type
- Multiple Archive Pages for Custom Post Types AND Taxonomies
- Exclude current post when getting related post on custom post type and taxonomy
- Display Posts of a Category in Alphabetical Order (Custom Post Type)
- How to query different post types in specific order?
- Loop on front-page.php
- Display custom post type from dynamic custom field
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- How to create database table, add data, update and delete using wpdb via plugins?
- Custom-Posttype & Custom Taxonomy WP_Query
- Stuck in Order by more then one
- Display featured image from one CPT within another CPT query
- How do you paginate a query grouped by month?
- Why is my category template ignoring post type?
- pagination not working for category.php (custom post types in categories)
- Query based on custom fields start and end date
- Retrieve custom post types by custom taxonomies with WP_Query
- Different Limit number of post on different archive page
- DIsplaying URL of custom field in last post of certain taxonomy && post type
- Using page slug in wp_query
- Custom taxonomy wp_query woes.
- Different options per post type in WP_Query
- Custom Category Walker with Image, Fallback to Most Recent Post in Category Image
- Custom Post type loop with ACF not displaying properly
- Sort results without WP_QUERY?
- Using Wp_Query, Json to add Highcharts series data
- Display the current post in browser as the first post in a loop (for a slideshow)
- How to query Posts from a custom post type which contains a custom taxonomy?
- Get_the_term_list inexplicably adds values in foreach
- Single parent post lists child posts with pagination
- custom taxonomy pagination 404 error
- wp_query can’t get max_num_pages in custom post type
- After inserting new post with wp_insert_post() the post is not visble to WP_Query, but the same WP_Query works for post inserted from wp-admin panel
- Filter in Custom post type to find the parent post
- “BS_” rows in postmeta table
- how to display posts content on the custom css popup by clicking on each title on the sidebar?
- How do I insert a custom post type query after a certain number of recent posts and then resume recent posts?
- how to display new private message to users?
- subtracting the current post form then whole loop, which is generating all CPT titles
- Displaying WordPress posts from post and custom post type in custom taxonomy
- Imported Content Doesnt Show Up On Frontend
- Loop carousel slider in wordpress
- Manually build WP_Query
- Custom Post save causes 500 error
- Loop with Custom Post Type and Taxonomies
- How to load more custom type posts through AJAX & LOAD MORE POSTS button
- Pagination always adding “Next” link when results come from Custom Post Type WP_query
- 404 on Pages for Custom Post Type & Query_Posts
- Is it possible to make is_category() recursive?
- Get X posts with the same terms as the current post (custom post type and custom taxonomy)
- How can I show posts with the same tag?
- Load posts via AJAX without draft status
- Uploading to WordPress Database
- WP Query – Can’t get posts with specific taxonomy