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

Is there a way to list tags order by post_meta field

$querystr = ” SELECT DISTINCT — post_meta.meta_value, key2.name as tag_name,key2.slug as tag_slug FROM $wpdb->posts key1 LEFT JOIN $wpdb->term_relationships ON (key1.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->postmeta post_meta ON (key1.ID = post_meta.post_id) LEFT JOIN $wpdb->terms key2 ON ($wpdb->term_relationships.term_taxonomy_id = key2.term_id) LEFT JOIN $wpdb->term_taxonomy key3 ON ($wpdb->term_relationships.term_taxonomy_id = key3.term_id) WHERE 1=1 AND post_meta.meta_key = ‘likes_count’ AND post_meta.meta_value > … Read more

Categories plugin-development Tags plugin-development, post-meta, tags

update_post_meta not working in save_post

A little late, but I just had this issue where adding a taxonomy term was working, but adding post meta wasn’t. The solution was to set a higher priority. The default priority is 10, so try for instance priority of 100: add_action( ‘save_post_dealer’, ‘save_dealer_long_lat’, 100, 1);

Categories save-post Tags post-meta, save-post

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

Regenerate missing _wp_attachment_metadata

Running the wp media regenerate command from WP-CLI with the –only-missing argument is quite fast (takes about 30 seconds for 4000 images) and rebuilds _wp_attachment_metadata correctly: wp media regenerate –only-missing

Categories images Tags attachments, images, media-library, 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

Show metabox in custom-post-template depending on taxonomy term?

This question is possibly a duplicate of: Only show metabox when date-value in other metabox is over? Broadly there are two ways of achieving this. Using the add_meta_boxes hook to pass two variables: post type and the post. Then add the metabox only when the post has a certain term: add_action( ‘add_meta_boxes’, ‘myplugin_add_my_custom_box’,10,2); function myplugin_add_my_custom_box($post_type,$post){ … Read more

Categories custom-post-types Tags custom-post-types, custom-taxonomy, metabox, post-meta

Adding Multiple Values to a Post Meta Key

You can insert an associative array into the post_meta_field. Here is a quick little function to grab the data afterward (did not test): function grab_task_name_array($post_id) { $new_array = array(); $array = get_post_meta($post_id,’_task-name’); //do not put true as third parameter (this would return string and not array) foreach($array[0] as $key => $value) $new_array[$key] = $value; return … Read more

Categories posts Tags custom-taxonomy, post-meta, posts, taxonomy, terms
Older posts
Newer posts
← Previous Page1 … Page169 Page170 Page171 … Page204 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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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