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

Advanced search form with filters for custom taxonomies and custom fields

I think something like this you would be best writing yourself. Take a look at: http://www.catalysthomes.co.uk/homes-for-sale/ Properties are loaded into a CPT and I have my own custom search in the sidebar. Of that search its searching a number of things such as taxonomies, custom fields and ordering by date price etc. So how do … Read more

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

Post meta vs separate database tables

Well, if I take the hat of a WP script kiddie, my answer would be: use post_meta, always. However, I happen to know a thing or two about databases, so my answer is: never, ever, ever, use an EAV (aka the post_meta table) to store data that you might to need to query. On the … Read more

Categories plugin-development Tags database, plugin-development, post-meta

Can I exclude a post by meta key using pre_get_posts function?

I see many people prefer to use pre_get_posts hook instead of query_posts Yay! So pre_get_posts filters a WP_Query object which means anything you could do via query_posts() you can do via $query->set() and $query->get(). In particular we can make use of the meta_query attribute (see Codex): $meta_query = array( array( ‘key’=>’featured’, ‘value’=>’yes’, ‘compare’=>’!=’, ), ); … Read more

Categories custom-field Tags custom-field, featured-post, post-meta, pre-get-posts

How to extract data from a post meta serialized array?

Use unserialize() to convert it into an array. $mydata=”a:5:{s:9:”engine_id”;a:1:{i:0;s:9:”300000225″;}s:15:”transmission_id”;a:1:{i:0;s:6:”257691″;}s:5:”plant”;a:1:{i:0;s:23:”Oshawa, Ontario, Canada”;}s:15:”Manufactured in”;a:1:{i:0;s:6:”CANADA”;}s:22:”Production Seq. Number”;a:1:{i:0;s:6:”151411″;}}”; $mydata = unserialize($mydata); echo $mydata[‘Manufactured in’][0]; Edit– Related thought- something to keep in mind when storing meta data serialized like this is that you limit your ability to use that data in queries, if that’s a concern for you. for instance, … Read more

Categories post-meta Tags array, post-meta

Explanation of update_post_(meta/term)_cache

Object cache everywhere WordPress tries to reduce the number of database queries as much as possible. For example, anytime you get a meta field or a taxonomy field, before querying the database, WordPress looks if that that was already queried and stored in cache, and returns it from there instead of querying the database. The … Read more

Categories post-meta Tags cache, core, customization, post-meta, terms

How to hook update_post_meta and delete_post_meta?

The update_post_meta hooks are called from the more generic update_metadata() function, so you might not have found it directly. The three hooks are: update_post_metadata, a filter which allows you to “hijack” the metadata update and do something else. If you hook up a function that returns a boolean, execution stops there and the boolean is … Read more

Categories hooks Tags hooks, post-meta

what is the correct way to compare dates in a WP query_posts meta_query

I wound up working on the exact same thing and this post was very helpful. I used Custom Fields and here is the code that I used to create a list of all events greater than the current date. Note the extra taxonomy based filters. <?php // Let’s get the data we need to loop … Read more

Categories custom-post-types Tags custom-field, custom-post-types, customization, post-meta, query-posts

Can the Next/Prev Post links be ordered by menu order or by a meta key?

Understanding the internals The “sort” order of adjacent (next/prev) posts is not really a sort “order”. It’s a separate query on each request/page, but it sorts the query by the post_date – or the post parent if you have a hierarchical post as currently displayed object. When you take a look at the internals of … Read more

Categories custom-post-types Tags custom-post-types, next-post-link, post-meta, previous-post-link, sort

Get posts by meta value

What you are asking for is a meta_query $args = array( ‘meta_key’ => ‘custom-meta-key’, ‘meta_query’ => array( array( ‘key’ => ‘cp_annonceur’, ‘value’ => ‘professionnel’, ‘compare’ => ‘=’, ) ) ); $query = new WP_Query($args); All of the information you need is in the Codex.

Categories post-meta Tags post-meta

How to only display posts whose meta_value field is not empty?

Hi @Rob: The reason you can’t figure out how to do it is because it’s not possible, at least not without resorting to SQL. Try adding the following to your theme’s functions.php file: add_filter(‘posts_where’,’yoursite_posts_where’,10,2); function yoursite_posts_where($where,$query) { global $wpdb; $new_where = ” TRIM(IFNULL({$wpdb->postmeta}.meta_value,”))<>” “; if (empty($where)) $where = $new_where; else $where = “{$where} AND {$new_where}”; … Read more

Categories wp-query Tags meta-value, post-meta, wp-query
Older posts
Newer posts
← Previous Page1 … Page201 Page202 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