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
0
votes
1 answer

Bug in update_post_meta? String changing

When i try to execute this code update_post_meta( $id, "_woocommerce_my_meta", 'a:1:{s:4:"gtin";s:13:"10";}' ); The meta was changing to s:27:"a:1:{s:4:"gtin";s:13:"10";}"; By simply changing the code to update_post_meta( $id,…
Emanuel
  • 2,603
  • 22
  • 24
0
votes
1 answer

Wordpress get max post meta between values

I already have a query like : SELECT max(cast(meta_value as unsigned)) AS max_racer_nr FROM wp_postmeta WHERE meta_key='racer_nr' I need to get max racer_nr which is between 1 - 99 or 100 - 199, or 200 - 999 depending on which class racer belongs…
Scorpioniz
  • 1,421
  • 3
  • 16
  • 36
0
votes
1 answer

Strip and streamline the "_wp_attachment_metadata" in Wordpress

000 "_wp_attachment_metadata" in mySQL for about 50k images on my blog and it's slowing down my WP site significantly. I've checked the field and found it contain almost nothing significant .. most looked like…
Edmund Fong
  • 101
  • 1
0
votes
1 answer

Automating update_post_meta

So i have been working on this legacy code and I'm trying to improve it a bit. I have this piece of code, which saves a bunch of custom fields from a post. if(isset($_REQUEST['unidade-dir1-cargo'])){ update_post_meta($post_id,…
bfagundes
  • 95
  • 2
  • 4
  • 16
0
votes
1 answer

Get custom fields without _edit_last, _edit_lock, _wp_page_template and _visual-subtitle

I'm getting custom fields using ID); ?> $value) { ?> '; ?> and it is showing _edit_last: 1
_edit_lock:…
w3debugger
  • 2,097
  • 19
  • 23
0
votes
2 answers

woocommerce POS pos only meta_query not working with display shop page as categories

I am trying to remove items from my shop that either have 0 stock or are marked to be POS only but for some reason only the 0 stock part works. Here is my code. What am I doing wrong? /**** Functions to remove items from store that have 0…
Leo
  • 1,495
  • 23
  • 41
0
votes
0 answers

Post loop output of variable

I have a archives-movies.php which outputs the information I want. In the $rat variable, I wanted to output the value as well as an image that I have uploaded to theme directory/img/stars/ with separate folders for the output as in folder 0,1,2,3,4…
scottiescotsman
  • 73
  • 2
  • 12
0
votes
0 answers

update post meta not working when called from updated_post_meta hook

I am adding (insert) into a non-Wp table soon after a specific post meta is updated this part works fine but when on the same function I try to update an another meta of the same post with the inserted ID of non-wp table. Post meta does not update.…
0
votes
1 answer

how to add custom post meta to add / update all posts in Wordpress

i need to add some detail to posts, so i have to modify page to add/update post but i don't know what action i should to use i want to add two select boxes, admin must select first field and then choose second too for example fields are : List One,…
Hossein Kurd
  • 3,184
  • 3
  • 41
  • 71
0
votes
1 answer

Change the count of post views in fuction by random number

I have this function in a wordpress theme : // function to count views. function setPostViews_anthemes($postID) { $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ $count = 0; …
Faouzi.A
  • 11
  • 2
0
votes
0 answers

MySQL Update with Sub Select for ACF Repeater Count

My Wordpress database somehow got messed up. I am using ACF repeater fields and the repeater count shows zero even though I have as many as 12 repeating elements. I am trying to update the repeater count so the field values will properly display…
Bryan
  • 17,201
  • 24
  • 97
  • 123
-1
votes
1 answer

Wordpress - save frontend submission form field as custom field

I use WP plugin for submitting posts from frontend. It's a field builder. Maybe it uses wp_insert_post() function, I really don't know. Here I use my custom shortcode, please check here for the code: function my_custom_shortcode() { global…
Juraj
  • 33
  • 5
-1
votes
1 answer

WP updating post_meta associative array with Ajax

I'm cycling through an associative array and adding each child array as a row in a table. The last column in that table is a button in which I want to use to remove that array from the parent array in the database. Here's my…
-1
votes
1 answer

How can I get results of a meta_value with "order by ASC" date in a postmeta value?

``` table = postmeta post_id = '1521'; meta_key = 'store_data'; meta_value =…
jmart
  • 1
  • 2
-1
votes
2 answers

how to fetch value from json formate wordpress

a:1:{s:9:"image_url";a:2:{i:0;s:62:"http://localhost/wordpress/wp-content/uploads/2021/04/g4-5.jpg";i:1;s:62:"http://localhost/wordpress/wp-content/uploads/2021/04/g1-2.jpg";}} Above is my data. I am using WordPress and I retrieve those data from…