You would have to JOIN
a couple of tables.
SELECT meta_value FROM wp_postmeta as pm
INNER JOIN wp_term_relationships as tr ON (pm.post_id = tr.object_id)
INNER JOIN wp_term_taxonomy as tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
WHERE 1
AND tt.taxonomy = 'laptop'
AND pm.meta_key = 'quantity'
I am fairly sure that is right. These things are complicated.
If your meta_value
is a number– that is, no punctuation or other spaces– you should be able to use SUM(meta_value)
and avoid the array_sum
after the fact.
Related Posts:
- Custom field values to taxonomy terms
- Woocommerce Custom Meta Boxes- How to only display if they actually have content
- ACF – Can’t get custom post type by taxonomy
- I want to show image from custom field image on my custom page template
- How do I organize posts based on their taxonomy?
- Most efficient way to add javascript file to specific post and/or pages?
- Display all values of custom a field created with ACF on a page
- How to automatically apply woocommerce product title to all product images alt tags?
- If Custom Field is empty don’t display div
- How to make an meta_query optional?
- WP_Query | Help me create a search term with an ‘OR’ relation?
- Add custom field to attachments in a specific category
- How can update custom meta for all posts
- get_post_custom single array
- WP_Query use for a filter with multiple Taxonomies and Terms
- Make custom field meta not display if there is not data in it
- Display Post co-authored in Author Page
- how to increase custom post value by one most efficiently?
- get_the_terms – only top level
- Get Custom URL For Custom Taxonomy
- How can I create a list of page titles from custom meta values?
- Custom profile field with birthday. Troubles with
- Why my filterable portfolio page work not perfectly between slug button and slug output WORDRPESS?
- wordpress allow user to edit user profile with custom fields
- Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
- Grab posts by multiple categories
- How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
- How to use thumbnail size of image if I’m only using src to get image
- 3 Slashes appear after Apostrophe in custom fields after updating product-site
- How to split links generated into an xml sitemap to avoid exceeding 30 sec maximum execution time?
- Trying to retrieve post meta
- Pull Tags But Not as Links
- How to combine 2 php functions into one function with a custom field
- Advanced Custom Fields – display label and value only if value entered
- Is it possible to retrieve all posts with a certain value for metadata?
- Saving zero in meta box
- Why does this update_post_meta function not delete the custom field itself?
- Ajax filter button display all posts
- Hierarchical taxonomy list with modificated term links
- WordPress loop by meta key that is an array? and how loop multiple arrays
- if custom field doesn’t exist, use post thumbnail instead, as image background
- Exclude product attributes from taxonomy terms loop
- WP All Import / Update stock quantity from multiple XML files
- How to store multiple custom meta box
- How to insert wp_users ->user login name to wp_terms when a new user registering?
- Concatenate Custom Field Value & HTML Value
- `update_post_meta` not working anymore
- Storing content into a custom taxonomy
- Define category ID using get_post_meta
- Check in which custom taxonomy belongs and change the style
- Hide a div when a custom field is empty
- Adding custom url to readmore link using get_permalink()
- Filter unique custom field value based on custom taxonomy category or other custom field
- Display movies that apear this day next
- Add “alt” Attribute to GD Star Rating Tags
- How to break up php code to avoid echo
- Display background color or image with custom meta box?
- custom header text
- Can ‘Custom Field’ data be inserted into this Short Code?
- Query pulling a single post per month
- Add custom fields from different posts
- Hi need update in my terms for other taxonomy
- WordPress: Export/Import Yoast meta title & description to custom taxonomy
- Delete images from media library when user deletes an image from ACF Gallery
- Adding a custom meta field with default NULL value which is not selectable
- Order category posts by last word of custom field
- Display acf taxonomy attachment
- Get taxonomy terms that share a common object property
- Products listing check if meta checkbox is checked
- How to update custom fields when post is published?
- Block error message in foreach loop when looping through ACF field
- Hide a div if the fiels is empty
- Inserting a class on before_widget if checkbox is checked
- Categories does not show Block editor WordPress
- What is the correct way to search 3 custom fields only in WordPress?
- wp_get_nav_menu_items() with ACF
- Filtering custom posts by using checkboxes for taxonomy in an ajax loop always gives server 500 error
- How do I get the value of a current user’s custom field?
- How to separate the taxonomies list from the form so that editing taxonmies is the same as pages and posts?
- Add Custom Taxonomy into Script
- How to display custom field from a gallery thumbnail?
- Getting a value from a custom field from a page that shares a parent with the current page
- Custom fields changes the formatting of metabox input
- Display Content Based on Custom Field Value
- enumerating custom taxonomies?
- If custom field doesn’t exist, or exists and it’s true show title?
- Custom field in title
- How can I put a custom field as the link of a button shortcode?
- Outputting a custom field in PHP
- Custom fields randomly stop working
- Where can I find the code for the menu page meta boxes?
- Query specific posts per user selections from dropdown menus
- How to echo a different field if another field is empty?
- PHP Puzzle: Unique Styles with PHP loop
- I want Page titles and excerpts to show up on home.php in certain order
- Metadata on the WP_Post object
- Appending an ACF custom field to the page title
- How do I change the Go To Categories link in the term_updated_messages
- Convert custom field date format to “WordPress default”
- How to execute a shortcode within a custom field?