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

Reduce or prevent calling of update_meta_cache

Whenever you use the function get_post_meta(), the above query will be performed to get all post meta and store in the cache. The more posts you query, the more queries are made. To reduce the number of queries, we should pre-cache all meta values of all posts in the query before calling get_post_meta. This is … Read more

Categories wp-query Tags post-meta, pre-get-posts, wp-query

Update CPT meta data using REST API

On the initial issues, are you positive the plugin is registering the fields to be made available to the api? the register_meta needs show_in_rest => true assigned. Also, the CPT needs custom-fields in its supports array, ‘supports’ => array(‘title’,’editor’,’thumbnail’,’custom-fields’) for that to made available when accessing the CPTs api endpoint. I cover that (with links, … Read more

Categories custom-post-types Tags custom-post-types, post-meta, rest-api

Get a single post by a unique meta value

I am just incredible stupid here as this can be easily done by a simple WP_Query: new WP_Query( array( ‘post_type’ => ‘shop_order’, ‘meta_key’ => $meta_key, ‘meta_value’ => $meta_value ) ) However, I decided to compare the actual generated SQL of the get_posts() with a ‘post_where’ filter solution which is: SELECT wp_posts.ID FROM wp_posts WHERE 1=1 … Read more

Categories post-meta Tags post-meta

How to get all custom fields of any post type

Add the following code in the functions.php for acf function get_all_meta($type){ global $wpdb; $result = $wpdb->get_results($wpdb->prepare( “SELECT post_id,meta_key,meta_value FROM wp_posts,wp_postmeta WHERE post_type = %s AND wp_posts.ID = wp_postmeta.post_id”, $type ), ARRAY_A); return $result; } function acf(){ $options = array(); $acf = get_all_meta(‘acf’); foreach($acf as $key => $value){ $options[‘post_type’][$value[‘post_id’]][‘post_id’] = $value[‘post_id’]; $test = substr($value[‘meta_key’], 0, 6); … Read more

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

Custom field values deleted when trashing custom post type

It seems that the action save_post gets fired when sending a post to the trash… Therefore, my custom metadata save function was being activated with no $_POST data to send thru it. To circumvent this, I wound up adding a nonce to the save function. function wpg_testimonial_author() { global $post; $custom = get_post_custom($post->ID); $testimonial_author_name = … Read more

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

Code to make a post sticky

The sticky posts are saved as an array of post IDs in the wp_options table. Hence, $stickies = get_option( ‘sticky_posts’ ); $stickies[] = $post_id; update_option( ‘sticky_posts’, $stickies ); will make the post in question sticky. EDIT: Even better, the core provides functions to stick and unstick posts (had to have ’em). stick_post( $post_id ); unstick_post( … Read more

Categories posts Tags post-meta, posts, sticky-post

WordPress database error: [Not unique table/alias: ‘wp_postmeta’]

You JOIN two elements both with the same table. When you need to join one table more than once, you need to make each join unique by giving the table alias. When WP makes the whole query, it takes that into account, but you have added your own code that doesn’t do that. So, first … Read more

Categories custom-taxonomy Tags custom-taxonomy, post-meta, search

How can I retrieve multiple get_post_meta values efficiently?

The way your code is setup is just wrong, you are making two database calls for each custom field and if you have between 2-30 fields like this then that means you make over 60 calls to the database which can be done with a single call using get_post_custom() for ex: $custom_fields = get_post_custom($post->ID); for … Read more

Categories posts Tags metabox, post-meta, posts

Lack of composite indexes for meta tables

A standard WordPress schema “sync” via dbDelta() will only add indexes, not drop them. Same goes for fields. We never touch the storage schema either, so it’d be the default for MySQL (which in latest versions is now InnoDB). On the face, a comment_id_meta_key index makes perfect sense. But when you look at how WordPress … Read more

Categories post-meta Tags comment-meta, mysql, post-meta

update_post_meta and update_field ony working when saving the post

The problem is that the function update_field from ACF works a little bit different from update_post_meta. Can you see it? update_post_meta( $post_id, $meta_key, $meta_value, $prev_value ); update_field( $field_key, $value, $post_id ); If you use update_post_meta you should in my opinion use get_post_meta to get the meta. If you use update_field you should use the_field or … Read more

Categories advanced-custom-fields Tags advanced-custom-fields, post-meta, save-post
Older posts
Newer posts
← Previous Page1 … Page195 Page196 Page197 … 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