Questions tagged [post-meta]

Post meta is a data set in WordPress that contains additional core as well as custom post information.

Post meta is a data set in WordPress that gets saved inside its own table named {$wpdb->prefix}_postmeta. It contains the following columns:

┌──────────┬──────────┬────────────┬──────────┐
│ post_id  │ meta_id  │  meta_key  │meta_value│
├──────────┼──────────┼────────────┼──────────┤
│ 1233456  │ 1234456  │     foo    │   bar    │
├──────────┼──────────┼────────────┼──────────┤
│bigint(20)│bigint(20)│varchar(255)│ longtext │
└──────────┴──────────┴────────────┴──────────┘

The post_id is needed to do JOINs, so the {$wpdb->prefix}_posts table can connect to this table.

The data that gets saved here by core:

  • _edit_lock
  • _edit_last
  • _thumbnail_id

This table also saves the data entered in custom fields.

And it's as well meant to hold additional custom data. If you want to search by custom field with a meta_query, it's better to use a single entry per value. Else you save it as serialized array (which core will do on it's own).

111 questions
6
votes
2 answers

WP_Query orderby meta_value_num not working

I'm trying to show list of services by price. I have setup the custom post type and custom fields etc. However, when I run the query on the page the most expensive service (£100) displays first instead of last... The query I've written is…
jonny-harte
  • 357
  • 1
  • 7
  • 16
2
votes
1 answer

How to show WooCommerce custom product meta in new order emails?

I'm currently successfully saving custom post meta for a single product as follows: function save_payment_terms( $product_id ) { if ( isset( $_POST['payment_terms'] ) ) { update_post_meta( $product_id, 'payment_terms',…
2
votes
0 answers

wordpress get posts with join custom table

i have created table in wordpress like this ///////////////////////////////////// | id | postid | userid | rating | | 1 | ahmed | 20 | 5 | | 2 | john | 13 | 3 | | 3 | sara | 49 | 10 …
ahmed_omar
  • 49
  • 7
2
votes
2 answers

Wordpress - Query comments by post meta

I am using the code below (simplified) to display a list of the last 10 comments: 'tarefa', 'number' => '10', 'order' => 'DESC', 'orderby' => 'comment_date', …
2
votes
3 answers

WordPress : how add new post meta before saving product woocommerce

i have a api from another wocommerce website and take some information with my product sku how can i add this information to post meta after created new product ? i wanna when i create a product , the information take with api and product sku and…
Mosi
  • 333
  • 1
  • 4
  • 15
2
votes
1 answer

Post meta titles not being found

I am trying to build upon and enhance the default wordpress search so that you can search pages and custom post type meta data as well. It works great, except custom field titles are not being output. I do print_r($custom_fields); and it shows that…
alexmattorr
  • 362
  • 4
  • 15
1
vote
2 answers

wordpress $query->set to sort archive product pages, by *manipulated* ACF meta key value

I am trying to use the pre_get_posts action hook to sort products by ACF field for archive product pages. The ACF field is a string, that contains characters and numeric value My solution: to add missing leading zero's so that '040' < '180' will…
Mulli
  • 1,598
  • 2
  • 22
  • 39
1
vote
1 answer

Post meta vs separate database tables

there is one big question in my mind why do developer plugin use post meta for saving data on database ? why don't use separate tables ? i know that if you lot of data you will save data on seprate tables and data related post better save on…
1
vote
1 answer

wordpress phpadmin SQL database query to get results in columns

In my wordpress website I have multiple custom fields under post type 'home_decor', using the below query returns two field 'post id' and 'hd_product_description'. Currently, I am using this query to export fields one by one and then vlookup by post…
1
vote
2 answers

I can't update post meta for WordPress

I'm trying to define the image I took from a remote site as a featured image, but I can't do it. I tried 2 different methods below but neither of them worked. How can I do it, can you help me? Method 1 - doesn't work: $postmeta->meta_value =…
aross
  • 27
  • 4
1
vote
0 answers

Send post_meta to email wordpress

i have two custom fields, and i want to add it to asnwer-question plugin email, when user posts new question - i get email with question details and i need those two custom fields in that email. My custom fields (post_meta values): …
modeman
  • 31
  • 8
1
vote
0 answers

Use Select Query to get post id and meta_value from postmeta - woocommerce

I am trying to get meta_value from postmeta using SQL select query, but it returns wc_order_h8K0C1ODu2134 instead of meta_value which is Table No 10 global $wpdb; $order_id = $order->get_id(); $order_num = $wpdb->get_row( $wpdb->prepare(…
user1781038
  • 111
  • 3
  • 10
1
vote
1 answer

Woocommerce how to get meta value from the order object

I'm trying to get a custom meta data field from wc_order. I have to clarify that I'm not a pro in php and I have tried many ways to get field, with: get_meta() get_meta_data() get_post_meta( $order_id ) and so on... But none of them have worked. I…
1
vote
0 answers

WP_Query order by the sum total of a postmeta value

I am trying to create a custom query to order the posts by the sum of the values for the '_heateor_sss_shares_meta' key in the postmeta table. A sample of the values that I am working with…
user857629
  • 33
  • 4
1
vote
1 answer

Subquery returns more than 1 row with a Wordpress postmeta query

I am trying to pull data from a subsite's posts and postmeta tables: SELECT xyz_8_posts.ID, (select xyz_8_postmeta.meta_value from xyz_8_postmeta inner join xyz_8_posts on xyz_8_postmeta.post_id = xyz_8_posts.ID where xyz_8_postmeta.meta_key =…
Anthony
  • 722
  • 1
  • 9
  • 25
1
2 3 4 5 6 7 8