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

What’s the point of get_post_meta’s $single param?

In general, storing PHP serialized data in database in a bad idea. It can be easily understood if you use multple key-value pairs of data in one field row, that is, you use an array or a object with one meta key. Imaging a car as the object. You can set multiple meta values to … Read more

Categories post-meta Tags post-meta

Adding meta tag without plugin

Although I would advice you to avoid this and use a plugin for this work. Because only a dedicated plugin can help SEO. “WordPress SEO” from yoost is a great plugin for SEO. That being said, here is the code for adding meta description and keywords in header. Paste this in theme’s functions.php file. function … Read more

Categories post-meta Tags post-meta, seo

How to update_post_meta value as array

You do this: $item->content_multiple = get_post_meta($item->ID, ‘_menu_item_content_multiple’, true); Note how you set the third parameter of get_post_meta() to true, which means that only one value will be returned. If you read the docs, you will see that, if the third parameter is false, you will get an array with all the values for that meta … Read more

Categories post-meta Tags post-meta

Check if Post Title exists, Insert post if doesn’t, Add Incremental # to Meta if does

This would need a query. So building on your code: <?php $postTitle = $_POST[‘post_title’]; $submit = $_POST[‘submit’]; if(isset($submit)){ global $user_ID, $wpdb; $query = $wpdb->prepare( ‘SELECT ID FROM ‘ . $wpdb->posts . ‘ WHERE post_title = %s AND post_type = \’stuff\”, $postTitle ); $wpdb->query( $query ); if ( $wpdb->num_rows ) { $post_id = $wpdb->get_var( $query ); … Read more

Categories post-meta Tags post-meta, wp-insert-post

How can I get the post ID from a WP_Query loop?

get_the_ID() can (only) be used within the loop. This retrieves the ID of the current post handled by the loop. You can use it on it’s own if you need it only once: $dish_meta = get_post_meta( get_the_ID(), ‘dish_meta’, true ); You can also store it as a variable if you need it more than once: … Read more

Categories post-meta Tags post-meta

WordPress is stripping escape backslashes from JSON strings in post_meta

Doesn’t look like there’s any way to avoid it. The update_metadata() function, which is ultimately responsible for saving the meta, explicitly runs a stripslashes_deep() on the meta value. This function will even strip slashes from array elements, if the value were an array. Theres a filter that’s run AFTER that called sanitize_meta, which you could … Read more

Categories post-meta Tags json, post-meta

How to save an array with one metakey in postmeta?

You don’t need to loop through the values. Just use update_post_meta($post_ID, {key}, {array of vals}), it should do! <?php $poddata = Array( ‘pod_id’ => $this->pod_id, ‘url’ => $this->url, ‘name’ => $this->name, ‘description’ => $this->description, ‘service’ => $this->service, ‘status’ =>$this->status, ‘price’ => $this->price ); //Update inserts a new entry if it doesn’t exist, updates otherwise update_post_meta($post_ID, … Read more

Categories post-meta Tags 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

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
Older posts
Newer posts
← Previous Page1 … Page49 Page50 Page51 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