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

How to hook a filter to catch get_post_meta when alternate a custom field output?

After a lot of messing around with this, I think I found a fairly good solution here. I realize this is over a year after you asked but this was bothering me and I couldn’t find a good solution until now. The problem is that the get_post_metadata function doesn’t allow you to access the current … Read more

Categories filters Tags filters, post-meta

What is “meta_input” parameter in wp_insert_post() used for?

This part of wp_insert_posts() gives it away: if ( ! empty( $postarr[‘meta_input’] ) ) { foreach ( $postarr[‘meta_input’] as $field => $value ) { update_post_meta( $post_ID, $field, $value ); } } where we see how the post meta fields are updated/added with update_post_meta(). Here’s the inline description for meta_input: Array of post meta values keyed … Read more

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

Order by meta value or date?

If you can explain it in SQL, you can query for it! There are three places where we want to change the default query: SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_type=”post” AND (wp_posts.post_status=”publish”) AND wp_postmeta.meta_key = ‘startDate’ AND CAST(wp_postmeta.meta_value AS CHAR) < ‘2011-03-23’ GROUP BY wp_posts.ID ORDER … Read more

Categories query-posts Tags date-time, post-meta, query-posts

What is the index [0] for on post meta fields?

Each post meta key can have multiple values. So you get the values by default as an array; the first entry (0) is the oldest. get_post_custom() fetches all meta keys with their values. You could simplify your code with: $price = get_post_meta( $post->ID, ‘price’, TRUE ); $comake = get_post_meta( $post->ID, ‘coMake’, TRUE ); When the … Read more

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

Orderby meta_value only returns posts that have existing meta_key

As stated in @ambroseya’s answer, its supposed to work like that. Once you declare a meta query, even if you aren’t looking for a specific value, it will only query posts with that meta key declared. If you want to include all posts sort them by the meta key, use the following code: $args = … Read more

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

Correctly delete posts with meta and attachments [duplicate]

@s_ha_dum suggests that Post meta will be deleted automatically. Therefore because his reputation suggests he knows what he is talking about, this solution only handles Post attachments. I’d suggest checking out the docs for the before_delete_post() hook, as it’s quite handy to be able to check out what Post Type is being deleted, etc. add_action(‘before_delete_post’, … Read more

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

Get post with multiple meta keys and value

This should do it. The default relation is AND so that won’t need to be specified. $args = array( ‘post_type’ => ‘wpse_cpt’, ‘meta_query’ => array( array( ‘key’ => ‘post_code’, ‘value’ => ‘432C’, ), array( ‘key’ => ‘location’, ‘value’ => ‘XYZ’, ), ), ); $query = new WP_Query( $args );

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

Use REGEXP in WP_Query meta_query key

Here’s one experimental idea: Assume we got: post A with the custom field location1 as UK – London post B with the custom field location2 as France – Paris post C with the custom field location3 as USA – New York Then we could use, for example: $args = [ ‘meta_query’ => [ ‘relation’ => … Read more

Categories wp-query Tags filters, meta-query, mysql, post-meta, wp-query

Difference between meta keys with _ and without _ [duplicate]

The underscore prefix are private, these meta fields will be hidden and will not be shown as custom fields in the post backend screens. Those meta fields without the underscore prefix are public fields and shows up as custom fields in the post screens

Categories custom-field Tags custom-field, post-meta
Older posts
Newer posts
← Previous Page1 … Page198 Page199 Page200 … 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