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

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

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

Function to change meta value in database for each post

You’ll only need to run it once, but this should get all your posts, and then loop through them and update the meta. add_action(‘admin_init’, ‘deleteCommaDB’); function deleteCommaDB(){ // The Query $args = array ( ‘posts_per_page’ => -1 ); $the_query = new WP_Query( $args ); // The Loop while ( $the_query->have_posts() ) : $the_query->the_post(); $price_key = … Read more

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

Custom fields: In what order are they saved into the DB?

The SQL query triggered by get_post_custom() is in update_meta_cache() and it looks like this: $wpdb->get_results( $wpdb->prepare( “SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list)”, $meta_type ), ARRAY_A ); So there is no ORDER BY given. Without ORDER BY the resulting order is almost unpredictable: it depends on the optimizer, used indexes and their … Read more

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

Custom fields to save multiple values

First, dd this code [] at the end of your form field name. So your field’s name will be “test[]”. Example: <input type=”text” name=”test[]” value=”” size=”60″ /> Use this way to save the value: $old = get_post_meta($post_id, ‘your_meta_key’, true); $newtest = array(); $test = $_POST[‘test’]; $count = count( $test ); for ( $i = 0; … Read more

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

Exporting Data from WordPress into a flat table

Problem is that meta values are not unique key/value data. E.g. with the key ‘OneKey’ you can have a lot of values for the same post. So, in a flat table, for the column ‘OneKey’ you should have multiple rows where the post id is the same and seems to me is not what you … Read more

Categories posts Tags database, export, meta-query, post-meta, posts

How to add multiple featured image in meta box in post editor?

I know you said you were looking for your own implementation, but the easiest way to add multiple featured image metaboxes is with the Multiple Post Thumbnail plugin. Following the plugin’s documentation, the way to define a secondary box is to add this code to your theme’s functions.php if (class_exists(‘MultiPostThumbnails’)) { new MultiPostThumbnails( array( ‘label’ … Read more

Categories custom-post-types Tags custom-post-types, metabox, plugin-development, post-meta, post-thumbnails

How to keep a check box in custom meta box for custom post type checked by default for add new post?

save_post being called multiple times is expected behavior, but because of how it’s used, you may not always want your code to execute until the user actually clicks on the save button. Like you have mentioned above regarding your requirement. So you can check the current page ( i.e post-new.php ) in the wp-admin and … Read more

Categories custom-post-types Tags custom-post-types, metabox, post-meta
Older posts
Newer posts
← Previous Page1 … Page168 Page169 Page170 … 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