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 fire join query with post_meta

Milo told you the answer. You need to store your data as individual keeps in the database rather than as a serialized array. MySQL cannot natively parse a serialized array though I have seen very complicated SQL that will. Still, that code is not going to be useful on a production server. It is too … Read more

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

Delete all post meta except featured image

The below code will help you to remove all the post meta’s except the thumbnail of a post. function kv_delete_all_meta_except_featuredimg(){ $args = array( ‘posts_per_page’ => -1, ‘post_status’ => ‘any’, ‘post_type’ => array(‘attachment’, ‘page’,’post’)); $articles= get_posts( $args ); foreach($articles as $article){ if($article->post_type == ‘attachment’){ $myvals = get_post_meta($article->ID); foreach($myvals as $key=>$val) { if($key == ‘_wp_attached_file’ || $key … Read more

Categories Database Tags database, mysql, phpmyadmin, post-meta, post-thumbnails

Assign category using custom field?

You should hook into save_post and set the categories using wp_set_object_terms(): // Add an action to run on post save add_action( ‘save_post’, ‘set_genre_on_save’ ); function set_genre_on_save( $post_id ){ // Check the post type if (is_single(‘tvseries’)) { // Get the custom field data $custom_field_data = get_post_custom( $post_id ); // Check if there is any genres entered … Read more

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

How can update custom meta for all posts

How can update custom meta (likes) for all posts that have this meta? If you want to update every post that has this meta: See the returns field parameter and custom field parameters for Wp_Query to 1) retrieve only posts with that meta_key, and 2) to lighten query and only return the ids instead of … Read more

Categories PHP Tags custom-field, functions, php, post-meta

How to get sum of meta_values of a meta_key in wp_query according to conditions

WP_Query gets posts from the database, but it’s not a generic SQL query class, it should really be called WP_Post_Query, as WP_Query implies it can do any SQL. As a result, you need to do several things: Grab the posts you need Get their meta values for amount_to_paid using get_post_meta Add those values up using … Read more

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

update_post_meta() not working when used with WordPress action

So I installed the Yoast SEO plugin, and tested your code, and now I can positively say “neither no nor yes, but you could” to this question: Please help not sure whether I should use this along with transition_post_status transition_post_status is fired before the wp_insert_post action is fired, and the Yoast SEO plugin is actually … Read more

Categories post-meta Tags post-meta, post-status

How do I access post meta data when publishing a new post in Gutenberg?

The solution is to use a different hook which fires after post meta data has been saved by Gutenberg to the WP API. After reading this related discussion on Github and inspecting this code by n7studios, I discovered that rest_after_insert_post is a hook to use. So, the way to reliably check for the existence of … Read more

Categories post-meta Tags block-editor, 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
Older posts
Newer posts
← Previous Page1 … Page174 Page175 Page176 … Page204 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