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

Batch update a post meta field value of each post in Post Type

Take a look at the AJAX documentation, there are plenty of examples on this site and across the Googles to trigger a server event without refreshing the page. In this case, WP is listening to an AJAX call that looks like http://example.com/wp-admin/admin-ajax.php?action=wpse20160318_batch_update. When triggered, it’ll run through your batch process an output a JSON message … Read more

Categories PHP Tags automatic-updates, php, post-meta

Custom search for custom post meta with pre_get_posts interferes with WP search

Create a another filter to remove post title and post content remove search terms try this if this helpful for you add_filter( ‘posts_search’, ‘custom_post_search_author_do’, 10, 2 ); function custom_post_search_author_do($search, $query ){ if( ! empty($search) && $query->is_main_query() && !is_admin() && isset($_GET[‘search-type’]) && $_GET[‘search-type’] == ‘autor’ ) $search=””; return $search; }

Categories custom-post-types Tags custom-post-types, customization, post-meta, pre-get-posts, search

Trigger JS in custom meta box if a featured image is loaded/exists

I couldn’t find any WP specific event to hook in to. What you can do is set up an observer with a callback to respond to DOM changes using MutationObserver and check if the your featured image has been added in the callback. There’s no support in IE < 11 though, which may be a … Read more

Categories media Tags ajax, javascript, media, metabox, post-meta, post-thumbnails

Count posts with specific term_meta

$base_array = array( ‘posts_per_page’ => -1, ‘fields’ => ‘ids’, ‘post_type’ => ‘cpt’, ‘post_status’ => array(‘publish’), ‘date_query’ => array( ‘before’ => ‘next Saturday’, ‘after’ => ‘last Monday’ ), ‘tax_query’ => array( ‘taxonomy’ => ‘pas_here_taxonomy’ ‘field’ => ‘slug’, ‘terms’ => array( ‘hardware’, ‘software’), ‘operator’ => ‘IN’ ) ); $base = get_posts($base_array); echo count($base);

Categories custom-post-types Tags count, custom-post-types, custom-taxonomy, post-meta

how to increase custom post value by one most efficiently?

Enter WP_Post and the “magic” getter – did you know… $value = get_post_meta( $post->ID, ‘custom_field’, true ); …is the same as $value = $post->custom_field; So you can shorten your code to: update_post_meta( $post->ID, ‘custom_field’, $post->custom_field + 1 ); Note you cannot do $post->custom_field++ – since the property doesn’t actually exist, it can’t be modified. Read … Read more

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

Get all meta keys assigned to a post type

Answer by @Gareth Gillman definitely works but its an expensive query if we have hundreds of posts. The function below is less expensive and using the wp native function get_post_custom_keys() if ( ! function_exists( ‘us_get_meta_keys_for_post_type’ ) ) : function us_get_meta_keys_for_post_type( $post_type, $sample_size = 5 ) { $meta_keys = array(); $posts = get_posts( array( ‘post_type’ => … Read more

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

How to add meta data to WordPress posts?

I assume you are trying to add metadata to the header, such as Open Graph. To do so, you can hook into wp_head and output your content there directly. Add this piece of code to your theme’s (or your child theme’s) functions.php file: //Hook to wp_head add_action(‘wp_head’,’add_my_metadata’); function add_my_metadata(){ // Echo any content your wish … Read more

Categories post-meta Tags post-meta

How to Validate Post Meta type/extension (Video File Image File etc)

Post’s metadata can not and should not be used for validation. They can be easily manipulated. Post metadata simply stores “editable” strings or arrays, nothing more than that. The code you have copied is trying to fetch a metadata and check if its value is mp3. You can change a value of exe to mp3, … Read more

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

Delete all post meta except featured image Using SQL

I rewrote the function from the link in your question to SQL. Keep in mind that this script will also clear the page-templates assigned to the pages. Make a backup of the wp_postmeta table first. DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts p ON pm.post_id = p.id WHERE (p.post_type IN (‘post’, ‘page’) AND pm.meta_key … Read more

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

Checking if a post with certain meta value exists

One way would be to use get_posts function: $posts_with_meta = get_posts( array( ‘posts_per_page’ => 1, // we only want to check if any exists, so don’t need to get all of them ‘meta_key’ => ‘_sku’, ‘meta_value’ => ‘1’, ‘fields’ => ‘ids’, // we don’t need it’s content, etc. ) ); if ( count( $posts_with_meta ) … Read more

Categories posts Tags post-meta, posts
Older posts
Newer posts
← Previous Page1 … Page158 Page159 Page160 … 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