Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

post-meta

How metadata API works?

Q1 Yes, you can store serialized arrays as a single meta key, eg: update_post_meta( $post_id, ‘my_items’, array( 1, 2, 3, 4 ); Furthermore, you can store multiple values against a single meta key, eg: add_post_meta( $post_id, ‘my_items’, 1 ); add_post_meta( $post_id, ‘my_items’, 2 ); The latter is preferred because meta queries can be more efficiently … Read more

Categories post-meta Tags meta-query, post-meta

get_post_meta returns bool(false)

Apparently the serialized data got corrupt, calling the field by query got me this error. WordPress does not return an error when the serialized data is corrupt just a bool(false). Solved this by insert/update the serialized data in a base64_encode() and call it with base64_decode(). This seems to do the trick and data can be … Read more

Categories post-meta Tags post-meta

Add a post metadata if only the key and value does not exist

OK, so you have some code that uses add_post_meta and you want to make it add only unique values. The problem in here is that add_post_meta does exactly what it’s name is saying – it adds a post meta value. There is 4th arg for that function that’s called unique, but it work based on … Read more

Categories post-meta Tags post-meta

Get post from meta_key and meta_value

You can get using this using SQL global $wpdb; // For single record $wpdb->get_row(“SELECT post_id FROM $wpdb->postmeta WHERE meta_key = $param1 AND meta_value = $param2”); // For multiple records $wpdb->get_results(“SELECT post_id FROM $wpdb->postmeta WHERE meta_key = $param1 AND meta_value = $param2” ); Use this for query $args = array( ‘posts_per_page’ => 10, // -1 for … Read more

Categories post-meta Tags post-meta, sql

Get updated post meta on save_post action?

WordPress fires the updated_{$meta_type}_meta hook which fires after the metadata is updated. In your case, the hook would be updated_post_meta and you could have your function run on that hook instead of the save_post hook.

Categories post-meta Tags actions, post-meta, save-post, wpdb

Identifying Importer Posts

Two things I could imagine: Check the post_modified value. Maybe import creates a definitive timestamp that you could use. You’ll still have to save the import date somewhere so you can check against it. I do some post importing via a stream/HTTP response (this is not the native importer). During the import, I map my … Read more

Categories post-meta Tags bulk-import, import, post-meta

Are multiple values from get_post_meta guaranteed to be ordered?

Yes. get_post_meta() uses get_metadata() which in turn uses update_meta_cache() to retrieve the values. In the source code we see this part (comment mine) // $id_column is ‘meta_id’ $meta_list = $wpdb->get_results( “SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list) ORDER BY $id_column ASC”, ARRAY_A ); So the meta values will be ordered by meta_id … Read more

Categories post-meta Tags post-meta

How to add meta tag to wordpress posts filter?

There is not a standerized way to add HTML meta tags in WordPress but you can use wp_head action as a generic way to add meta tags. I think description meta tag should not be in the theme, as you suggest in your answer, because description meta tag is a property of the document, nothing … Read more

Categories post-meta Tags description, post-meta

Get posts by meta value with date

Depends what you are getting back from the ‘date_event’ post-meta field. That’s probably the culprit here — if it’s an actual date with a month and day, it’s not going to match what you are getting from date(‘Y’), which is just going to be ‘2018’. You can check the value in ‘date_event’ on any of … Read more

Categories post-meta Tags date, get-posts, post-meta

loop through all meta keys with get_post_meta

As @Sally CJ noted in the comment to your question, you should just omit the meta key: $meta = get_post_meta( $post->ID, ”, true ); echo $meta[‘car_year’]; // 2005 In PHP 7.1 you can use array destructing: [ ‘image_meta’ => $image_meta, ‘car_year’ => $car_year, ‘car_mileage’ => $car_mileage, ‘car_price’ => $car_price, ‘car_model’ => $car_model, ] = get_post_meta( … Read more

Categories post-meta Tags post-meta
Older posts
Newer posts
← Previous Page1 … Page42 Page43 Page44 … Page51 Next →
+ More

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
Next Page »
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress