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

Is there a way to extend WP_query so Custom Post Types can have properties?

Getting meta data from a WP_Post object is already possible. Just write: echo $post->your_meta_key; This will call get_post_meta( $this->ID, $your_meta_key, true ) behind the scenes. See the documentation and the source code for WP_Post. This works also with instances of WP_User, but not with WP_Comment as far as I know. Don’t forget to escape the … Read more

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

How we get_post_meta without post id

$post->ID is what makes the meta value distinguished across all posts with the same meta key. So if you want to shorthand the get_post_meta call for the current post you can do this: function get_cuurent_post_meta($key){ global $post; return get_post_meta($post->ID,$key,true); } and you can call it like this: echo get_cuurent_post_meta(‘custom_tags’.$userID); Now if its not the current … Read more

Categories post-meta Tags post-meta

Echo all meta keys of a custom-post TYPE

You can use a simple query to get a distinct list of user-entered meta_keys for a specific post type, then cache the results using the Transients API. The meta keys from this query will be those that do not start with an underscore or number. function generate_foods_meta_keys(){ global $wpdb; $post_type=”foods”; $query = ” SELECT DISTINCT($wpdb->postmeta.meta_key) … Read more

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

How to allow hidden custom fields to be added from wp-admin/post.php?

I found the following filter, here unlocking all protected meta data: add_filter( ‘is_protected_meta’, ‘__return_false’ ); Or it can be fine tuned: add_filter( ‘is_protected_meta’, function( $protected, $meta_key, $meta_type ) { $allowed = array( ‘_edit_lock’, ‘_test’, ‘_wp_page_template’ ); if( in_array( $meta_key, $allowed ) ) return false; return $protected; }, 10, 3 ); It allows to display the … Read more

Categories posts Tags post-meta, posts

Get meta_id along with meta_key and meta_value

This function worked for me: function get_complete_meta( $post_id, $meta_key ) { global $wpdb; $mid = $wpdb->get_results( $wpdb->prepare(“SELECT * FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s”, $post_id, $meta_key) ); if( $mid != ” ) return $mid; return false; } it will return an array of objects like: Array ( [0] => stdClass Object … Read more

Categories PHP Tags php, post-meta

if get_post_meta is empty do something

You could use the empty function inside your if as such : <?php if( empty( get_post_meta( $post->ID, ‘price_list_category1’, true ) ) ) : ?>style=”display:none;”<?php endif; ?> The above returns an error, you should assign the return value to a variable. See my edit below. Warning empty might not be the best option depending on the … Read more

Categories post-meta Tags post-meta

Admin Area Custom Type Search By Meta Fields Without Title & Content

There is a plugin called Search everything, where you can break down what you want to search. It does custom fields, posts and of course titles.

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

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
Older posts
Newer posts
← Previous Page1 … Page196 Page197 Page198 … 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