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
- is_main_query() not working for WP REST API
- is there a way to retrieve posts that do not have a featured image assigned?
- Group custom posts by custom taxonomy names
- How to call a custom post type with WP_query
- Custom Post Types not showing, custom WP_Query
- Deleting Custom Post type data using mySQL command
- Can’t get order_by meta_value_num to work properly
- How can i skip same post from taxonomy term?
- Custom Post Type + 20k posts = blank/404 within Admin edit.php [duplicate]
- WP_Query | ‘post_type’ doesn’t work
- How to connect two custom post types with nested loops
- Filter by custom taxonomy slug on a custom post type
- Custom Post type and Custom Field WP_Query
- Pagination on category page with custom post types
- Display multiple custom post types and sort them chronological by one of their fields
- Using DISTINCT in wp_query
- WordPress database error – Error in SQL syntax – I can’t identify any error?
- Using global $post; to get featured image for custom post via WP_Query
- Query custom post type in the loop
- How to add pagination to wp_query [duplicate]
- Related posts in all categories of current post (custom post types)
- Taxonomy Archive: Display only one post per term from separate custom taxonomy
- Loop through Custom Post Type, and then show children within each iteration
- Why does querying on post_tags (which has been applied to custom post types) only return posts?
- Sorting multiple custom post types without a meta key/value pair by sort order
- Including Custom Meta with posts_where query
- Very Slow Page – How to Optimize # of Queries?
- orderby in custom WP Query does not work
- Pagination : How to remove /page/x/ after a ‘POST’ action on a form returning to page 1
- Can I create a loop with multiple post types and specify different $args for each post type?
- Why is variable not working on custom sql query using wpdb?
- How to show CPTs in term archive
- Query custom post type by category slug
- Combining sorted and random CPT
- why update and delete query not worked in custom table?
- WP All Import – Using Xpath to set a select value
- How to add post_type=value when editing that post type in the WordPress admin?
- Display CPT posts based on specific taxonomy
- Can’t query tag and post_type at the same time
- Setting proper query for multiple custom admin filters
- shortcode to show custom post types by category
- Unable to retrieve any posts of CPT in wp-admin
- WP_Query: include custom post type only with specific meta value
- Pagination on a custom post type loop
- showing custom post types of a certain category only
- WP_Query orderby modified to include custom meta changes
- WordPress custom loop filter by meta_key and value with serialize data
- Returning a list of custom post types excluding those without a specific meta_value
- query private custom post type
- Display custom post type from dynamic custom field
- Query/list all terms and their custom post count
- Linking to the most recent post in a Custom Post Type
- How to make sure content doesn’t display if selection is empty
- Filtering WP_Query Dynamically on the Front-End
- Show one item per category of a custom post type
- Sorting custom post type columns with external data and without meta values
- Why get_posts() not returning only selected category posts from Custom Post Type?
- Storing posts from query and accessing later via AJAX call
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- Create WP_Query to search for posts by their categories or their parent/child categories
- Archive for custom taxonomy lists all posts instead of current taxonomy
- Genesis filterable portfolio isotope [closed]
- Query custom post type with tags
- wp_query check if integer exists in custom field’s array
- Add meta value to custom post type on publish
- Wrong request query on cpt and tax
- Advanced SELECT query with condtional statements