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 to sanitize post meta field value?

HTML in custom fields is, from my point of view, a weird use case of custom fields. Even more if the purpose of the used HTML is just look and feel (<strong> and <i> can be seen as just look and feel). It is really better if you use the HTML markup on the custom … Read more

Categories post-meta Tags post-meta, sanitization

Delete post meta conditionally after save post

Well, first use the hook properly. The post ID will be passed in. You don’t need $post->ID. Second, use the correct hook. If you want to run save_post only for your booking type, use save_post_booking But otherwise, the code works. I just ran a quick test. function booking_status_is_updated($post_id){ if(get_post_meta($post_id,’booking_status’,true)==’denied’){ delete_post_meta($post_id,’booking_slot’); } } add_action(‘save_post_booking’,’booking_status_is_updated’);

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

How can I get values using key in Carbon Fields from Multiselect?

One of the Carbon Fields developers here. Thank you for your feedback! Currently, the Carbon Fields stores only the keys and they don’t have a built-in method to retrieve the selected values from the options array. You can pass a callable which returns an array with the options as an argument to the add_options method. … Read more

Categories post-meta Tags post-meta

Metabox Data not being saved [closed]

If that is all of your code, you’re missing a save_post action to save the data. Refer to the code sample provided on add_meta_box. add_action( ‘save_post’, ‘save_my_meta_box_data’ ); function save_my_meta_box_data( $post_id ){ // make sure it’s not an autosave if ( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ) return; // verify your nonce if ( !wp_verify_nonce( … Read more

Categories post-meta Tags metabox, post-meta

Correct processing of `$_POST`, following WordPress Coding Standards

Correct processing of `$_POST`, following WordPress Coding Standards

Categories post-meta Tags coding-standards, post-meta, sanitization, save-post

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
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
  • 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