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 can I add a custom meta value on file upload?

Use added_post_meta and update_post_meta with the $post_id. For extended properties see this post and this for more image functions. add_action(‘added_post_meta’, ‘wpse_20151218_after_post_meta’, 10, 4); function wpse_20151218_after_post_meta($meta_id, $post_id, $meta_key, $meta_value) { // _wp_attachment_metadata added if($meta_key === ‘_wp_attachment_metadata’) { // Add Custom Field update_post_meta($post_id, ‘_example_meta_key’, ‘ex087659bh’); // _wp_attached_file // _wp_attachment_metadata (serialized) // _wp_attachment_image_alt // _example_meta_key $attachment_meta = get_post_meta($post_id); … Read more

Categories plugins Tags hooks, plugin-development, plugins, post-meta, uploads

Human Time Diff, change mins to minutes

You can do: echo str_replace(‘mins’, ‘minutes’, human_time_diff( get_the_time(‘U’), current_time(‘timestamp’) ) . ‘ ago’); Update: The same using filter as suggested: add_filter(‘human_time_diff’, ‘new_human_time_diff’, 10, 2); function new_human_time_diff($from, $to) { // remove filter to prevent the loop remove_filter(‘human_time_diff’, ‘new_human_time_diff’); $timediff = str_replace(‘mins’, ‘minutes’, human_time_diff($from, $to) . ‘ ago’); // restore the filter add_filter( ‘human_time_diff’, ‘new_human_time_diff’, 10, 2); … Read more

Categories posts Tags date, functions, post-meta, posts, timestamp

Compile meta values from custom loop into array and then calculate sum total

I wonder if you mean this kind of loop: $total_views = 0; $post_ids = [2, 3, 7, 53, 75]; foreach( $post_ids as $post_id ) { $total_views += (int) get_post_meta( $post_id, ‘post_views’, true ); } to calculate the total sum.

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

How to display liked posts of current user in wordpress?

Try the below $args instead, the one you have right now is looking for liked_by_user_id > than the current user id. $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => -1, ‘orderby’ => ‘date’, ‘meta_query’ => array( array( ‘key’ => ‘liked_by_user_id’, ‘value’ => get_current_user_id() ) ), ); The above $args should return all posts by liked … Read more

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

Short of raw SQL, can I query for multiple attachment metadata that have a given array key?

While you can do this with WP_Query, I’d do this the way you are trying to avoid– save a list in a separate key. The “pros” strongly outweigh the “cons” in my mind. LIKE queries with wildcards, especially with leading wildcards, are not efficient– aka, “slow” and a LIKE query on serialized data is going … Read more

Categories post-meta Tags attachments, post-meta, wpdb

Custom Meta Boxes – Nonce Issue – Move to trash issue

I had one more look at the code and I realized the save function was missing couple of checks. So replace meta_boxes.php:366 with this, if ( empty( $_POST[‘nonce_car_details’] ) ) { return; } check_admin_referer( ‘save_car_details_meta’, ‘nonce_car_details’ ); if ( ! current_user_can( ‘edit_post’, $post_id ) ) { return; } if ( wp_is_post_autosave( $post_id ) ) { … Read more

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

query posts in functions.php and update a field

You have to replace $post_id with get_the_id(); function status_alerts($query) { //start function global $post; // set the global $args = array( // all posts in the status post format ‘posts_per_page’ => -1, ‘taxonomy’ => ‘post_format’, ‘field’ => ‘slug’, ‘terms’ => array( ‘post-format-status’ ), ‘operator’=> ‘IN’ ); $alert_query = new WP_Query( $args ); while ( $alert_query->have_posts() … Read more

Categories wp-query Tags advanced-custom-fields, functions, post-meta, wp-query

Save attachment custom fields on front end

On the back-end, you’re retrieving the data like this: $meta = $_POST[‘attachments’][ $post_id ][‘photo_time’]; $meta_two = $_POST[‘attachments’][$post_id][‘photo_order’]; So on the front-end, you should set the field’s name in this format: attachments[<?= $vP ?>][KEY] where KEY could be either photo_order or photo_time. echo ‘<input type=”hidden” name=”attachments[<?= $vP ?>][photo_order]” class=”photo_order” value=”‘.$Por.'” />’; echo ‘<input type=”text” name=”attachments[<?= $vP … Read more

Categories custom-field Tags attachment-fields-to-edit, attachments, custom-field, forms, post-meta

Compare two meta key values against each other inside the get_posts array?

You can’t do this in the meta query I’m afraid. You’d need to get all the relevant records in meta query, then make that comparison inside PHP, to filter out the records you don’t need.

Categories PHP Tags array, php, post-meta

ajax delete value from custom field array

Try this: function delete_attachment() { $id = $_POST[‘att_ID’]; // the attachment ID // Deletes the attachment (and all of its custom fields or meta data; e.g. // `photo_order`). The `true` bypasses the trash. $att = wp_delete_attachment( $id, true ); // Deletes all custom fields named `vid_pix` where the value (`meta_value`) // is the attachment ID … Read more

Categories custom-field Tags attachments, custom-field, customization, post-meta
Older posts
Newer posts
← Previous Page1 … Page173 Page174 Page175 … 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