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
1
vote
1 answer

Why does this work outside a plugin's hook, but not inside?

please help me. What am I missing here? I created a plugin that creates a coupon with an order. And with the following, I want to attach the coupon's code to an email. The coupon is stored in an array in a custom postmeta field…
bndkt
  • 13
  • 4
1
vote
1 answer

add meta key and meta value to post in wordpress programmatically (woocommerce)

I woud like to add custom meta key and meta value in wordpress post for woocommerce products. I have code like this: global $wpdb; $post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts ORDER BY ID DESC LIMIT 1" ); add_post_meta($post_id,…
yoomla
  • 75
  • 8
1
vote
0 answers

Why is my $query->set('meta_query') not working for a field from the wp_posts table?

I have a field called post_title which is present in the wp_posts table and 2 custom fields - production_year and movie_description - these 2 custom fields are located inside the wp_postmeta table. I want to filter my posts of custom post type…
Hellios5
  • 11
  • 2
1
vote
0 answers

How to update post_meta from my custom post type that I got from another custom post-type?

I got successfully the meta_value called "rwp_user_score" from another custom post-type and save it as a variable called $meta_rwp_user_score. Now, I like to update that meta-value each time the value updated by the custom post-type. The code so…
meicelinho
  • 11
  • 1
1
vote
1 answer

Which is the best way to check if a post meta value exists?

Up until recently, I've always used the following method to check if a post meta exists: if(get_post_meta($post_id, 'example-key', true)) { echo get_post_meta($post_id, 'example-key', true); } This of course provides a fallback if the key…
Lee
  • 4,187
  • 6
  • 25
  • 71
1
vote
1 answer

Adding multiple radio buttons in featured photo meta box

I would like to provide the options to the editor to choose how the featured image cropped. I add three radio buttons(left, center, right cropped) in the feature image meta box. It was shown properly but not working when post updating. It do not…
Vis
  • 21
  • 1
1
vote
2 answers

Wordpress On Edit Post Page Save, Update Post Meta

I am trying to create/update post meta when you create/update a post that is specifically a post type of "offer". However, it does not update the post meta. This code is added in my functions.php file. add_filter( 'pre_post_update',…
Daniel Vickers
  • 1,054
  • 1
  • 12
  • 32
1
vote
1 answer

Wordpress Meta_Query open close time

I am trying to make a filter with open and closed checkbox using Meta_Query. The value of metadatas is UNIX time, so the value of $opening_time and $closing_time is number like this - 234321543. It only works without $status_2, $opening_time_2,…
Tod
  • 187
  • 3
  • 13
1
vote
1 answer

How to Assign Category to a Post Automatically using Postmeta

I've read other answers about assigning category based on post tags. But can this be done based on postmeta? I'm assuming it can be and I've been trying to change the following snippet (quoted in another answer) to achieve this. But I've had no luck…
BeckPerth
  • 31
  • 3
1
vote
1 answer

Use Shortcode in Shortcode (insert post meta field value)

i have a shortcode from a plugin which i cant modify... This shortcode has some arguments ex. [some_shortcode value=""] - I tried to input the value from post meta as argument for this shortcode, but its not working - here is the code... This is the…
LovinQuaQua
  • 111
  • 2
  • 12
1
vote
1 answer

Why are these values being saved as a string via update_post_meta?

I've just noticed that all of my values in this array, which are either integer or null, when I use update_post_meta, it stores both the integer and null value as a string, rather than an object. When I var_dump on the output from get_post_meta, I…
Lee
  • 4,187
  • 6
  • 25
  • 71
1
vote
3 answers

What's the best way to store post_meta value in variable, with a default value?

What's the most efficient and simplest way to store a post_meta value in a variable, along with a default value if the meta_key doesn't exist? I want to use something like this, the meta_value will always be a number: $bv_faq_thumbs_up =…
Lee
  • 4,187
  • 6
  • 25
  • 71
1
vote
1 answer

My custom post type importing empty value to database auto

I have made a custom post type with custom meta box. when i press "add new post" its auto importing input values to post_meta table. how can i fix it? i don't want to import before publish post. I have this code. function…
1
vote
0 answers

I want to show CMB2 meta fields on specific product category on backend

I need to show cmb2 meta fields based on specific product category in backend. Like there is a product is already assigned to t-shirt category and another product is assigned to shirt category. Both of them has separate cmb2 post meta. What I want…
Zahid
  • 33
  • 5
1
vote
0 answers

How to edit post meta data on Wordpress blog

I am trying to edit the post meta data on my Wordpress blog to include: Author(no link) Date(no link) Page(with affiliate link to page on my site) under every Post Title. I am using the Activello theme and have installed a child theme. I am trying…
saracee
  • 11
  • 4