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

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

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

What is the different between an attachment in wp_posts and an attachment in wp_postmeta?

An attachment is a Post The posts table contains information on the attachment post. In WordPress every uploaded media has it’s own post entry, where post_type is ‘attachment’ and post_status is ‘inherit’. In fact, you can get attachment post types using functions used to get other post types, like post, page or any CPT. That … Read more

Categories post-meta Tags attachments, post-meta, woocommerce-offtopic

What’s the point of get_post_meta’s $single param?

In general, storing PHP serialized data in database in a bad idea. It can be easily understood if you use multple key-value pairs of data in one field row, that is, you use an array or a object with one meta key. Imaging a car as the object. You can set multiple meta values to … Read more

Categories post-meta Tags post-meta

Adding meta tag without plugin

Although I would advice you to avoid this and use a plugin for this work. Because only a dedicated plugin can help SEO. “WordPress SEO” from yoost is a great plugin for SEO. That being said, here is the code for adding meta description and keywords in header. Paste this in theme’s functions.php file. function … Read more

Categories post-meta Tags post-meta, seo

How to update_post_meta value as array

You do this: $item->content_multiple = get_post_meta($item->ID, ‘_menu_item_content_multiple’, true); Note how you set the third parameter of get_post_meta() to true, which means that only one value will be returned. If you read the docs, you will see that, if the third parameter is false, you will get an array with all the values for that meta … Read more

Categories post-meta Tags post-meta

Check if Post Title exists, Insert post if doesn’t, Add Incremental # to Meta if does

This would need a query. So building on your code: <?php $postTitle = $_POST[‘post_title’]; $submit = $_POST[‘submit’]; if(isset($submit)){ global $user_ID, $wpdb; $query = $wpdb->prepare( ‘SELECT ID FROM ‘ . $wpdb->posts . ‘ WHERE post_title = %s AND post_type = \’stuff\”, $postTitle ); $wpdb->query( $query ); if ( $wpdb->num_rows ) { $post_id = $wpdb->get_var( $query ); … Read more

Categories post-meta Tags post-meta, wp-insert-post

How can I get the post ID from a WP_Query loop?

get_the_ID() can (only) be used within the loop. This retrieves the ID of the current post handled by the loop. You can use it on it’s own if you need it only once: $dish_meta = get_post_meta( get_the_ID(), ‘dish_meta’, true ); You can also store it as a variable if you need it more than once: … Read more

Categories post-meta Tags post-meta
Older posts
Newer posts
← Previous Page1 … Page49 Page50 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