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

Execute action after post is saved with all related post_meta records (data)

For NEW post type ‘post’ use draft_to_publish action hook: function fpw_post_info( $post ) { if ( ‘post’ == $post->post_type ) { // echo ‘<pre>’; print_r( $post ); echo ‘<br />’; // $meta = get_post_meta( $post->ID ); print_r( $meta ); echo ‘</pre>’; die(); // your custom code goes here… } } add_action( ‘draft_to_publish’, ‘fpw_post_info’, 10, 1 … Read more

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

Storing revisions of metadata for custom post type

There’s a private filter you can (but shouldn’t) access: Defined in wp-includes/revision.php: /** * Filter the list of fields saved in post revisions. * * Included by default: ‘post_title’, ‘post_content’ and ‘post_excerpt’. * * Disallowed fields: ‘ID’, ‘post_name’, ‘post_parent’, ‘post_date’, * ‘post_date_gmt’, ‘post_status’, ‘post_type’, ‘comment_count’, * and ‘post_author’. * * @since 2.6.0 * @since 4.5.0 … Read more

Categories custom-post-types Tags custom-post-types, post-meta, revisions

Using get_post_meta with new_to_publish

That’s because the fields weren’t set then. Note: The »Autosave« process/request also doesn’t save them. Use the values from $_POST instead for your “new_to_publish” action. EDIT: Do NOT forget to escape and properly sanitize input data! Else you will open a security hole.

Categories custom-field Tags custom-field, post-meta, post-status

What is the difference between update_post_meta and update_postmeta hooks?

They were both introduced in version 2.9, but were done so in different files. update_postmeta went into /wp-admin/includes/post.php While… update_{$meta_type}_meta went into /wp-includes/meta.php It was only later that update_postmeta was shifted into /wp-includes/meta.php. So I believe it was for backward compatability, where by because the update_postmeta hook was always receiving the value of maybe_serialize() then … Read more

Categories hooks Tags core, hooks, post-meta

post formats – how to switch meta boxes when changing format?

I did something like this once, but when you clicked on a certain category (essentially the same) It certainly isn’t a true ajax solution, it just hides and reveals the div with the settings, but It is a solution which works. You’ll definitely have to modify this for your needs, but if you have a … Read more

Categories post-meta Tags ajax, metabox, post-formats, post-meta

Sanitizing integer input for update_post_meta

For integers KSES has no special function. Use (int) or intval() or absint() See more: Data Validation – Integers

Categories post-meta Tags input, post-meta, sanitization

meta_query: using BETWEEN with floats and/or casting to DECIMAL

You can filter generated SQL and add precision parameters that you need. Enable filters for get_posts() by adding following to query: ‘suppress_filters’ => false, And: add_filter(‘posts_where’,’cast_decimal_precision’); function cast_decimal_precision( $where ) { return str_replace(‘DECIMAL’,’DECIMAL(10,3)’,$where); } Update With Jan’s suggestion: add_filter(‘get_meta_sql’,’cast_decimal_precision’); function cast_decimal_precision( $array ) { $array[‘where’] = str_replace(‘DECIMAL’,’DECIMAL(10,3)’,$array[‘where’]); return $array; }

Categories wp-query Tags get-posts, post-meta, wp-query

How to edit a post meta data in a Gutenberg Block?

Think I found the answer here. The first argument to register_meta is not post type but object_type, which is in my case should be post rather than taxonomy or comment. The function description, found here, states as of WordPress 4.9.2 the correct parameter is post. Once I switched it everything worked. register_meta(‘post’, ‘event_location’, [ ‘show_in_rest’ … Read more

Categories post-meta Tags block-editor, post-meta

Order by optional meta key?

Completely edited after first publish The problem is that to order for a meta value, WordPress need to ‘meta_key’ in query is set to something. But if you set ‘meta_key’ to something, then WordPress will add something like AND ( wp_postmeta.meta_key = ‘the_meta_key’ ) to WHERE SQL clause; and something like INNER JOIN wp_postmeta ON … Read more

Categories wp-query Tags order, post-meta, wp-query

Best way to programmatically remove a category/term from a post

Hmmm, can’t remember or find fitting function either. There is wp_set_object_terms() that is used in multiple wrappers like wp_set_post_categories(). It can overwrite categories for a post. So you can get post categories, check for unwanted one and write it back excluding unwanted in that case.

Categories custom-field Tags api, custom-field, post-meta, taxonomy
Older posts
Newer posts
← Previous Page1 … Page196 Page197 Page198 … Page203 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