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 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

Most efficient way to get posts with postmeta

Post meta information is automatically cached in memory for a standard WP_Query (and the main query), unless you specifically tell it not to do so by using the update_post_meta_cache parameter. Therefore, you should not be writing your own queries for this. How the meta caching works for normal queries: If the update_post_meta_cache parameter to the … Read more

Categories post-meta Tags post-meta, sql

Query all posts where a meta key does not exist

I did some more testing with this, and honestly can’t find a reason it wouldn’t work (unless the code above is just a snippet and the real code fits on my examples below). I did, however, discover a couple of things that might lead you in the right direction. 1) By itself, this meta query … Read more

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

How do I retrieve the slug of the current page?

Use the global variable $post: <?php global $post; $post_slug = $post->post_name; ?>

Categories post-meta Tags post-meta, slug
Newer posts
← Previous Page1 … Page203 Page204
+ 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
  • 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