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

Metadata on the WP_Post object

There is no ‘magic’ in it, but there are two magic methods of WP_Post class, __isset(), and __get(). Your extra_data is not a property of WP_Post class, so first var_dump does not include it. A reference to non existing property of WP_Post employs those magic methods, mentioned above, to retrieve post’s metadata. First, $post->__isset(‘extra_data’) will … Read more

Categories PHP Tags custom-field, php, post-meta

Use a Variable in update_post_meta as the $meta_key

There is an error in setting variable on this line: $week_s1=”_member_score_”.$week._s1″; this line should be $week_s1 =”_member_score_”.$week.”_s1″;

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

WP_query sort by custom meta_key “price”

Thanks to Brad Dalton at wpsites.net for getting me to the answer. Install Advanced Custom Fields plugin. Create a custom field called price, formatted as a number. Use the code below (based on Bill Erickson’s tutorial): add_action( ‘pre_get_posts’, ‘kr_change_posts_order’ ); function kr_change_posts_order( $query ) { if ( $query->is_main_query() && !is_admin() && !is_page() ) { $orderby … Read more

Categories posts Tags post-meta, posts, pre-get-posts, wp-query

How we insert values into database using metabox WordPress?

The following example is adding a meta box to the post edit screen and the wporg_cpt edit screen. function wporg_add_custom_box() { $screens = [‘post’, ‘wporg_cpt’]; foreach ($screens as $screen) { add_meta_box( ‘wporg_box_id’, // Unique ID ‘Custom Meta Box Title’, // Box title ‘wporg_custom_box_html’, // Content callback, must be of type callable $screen // Post type … Read more

Categories post-meta Tags meta-query, metabox, post-meta

Remove action of an external plugin after checking if custom post meta is set

According to the documentation for remove_action() the function name and priority must match the usage where the function was hooked. You have made a common sense assumption that a higher priority should be used for the removal but I believe that is the cause of the problem. Docs: https://developer.wordpress.org/reference/functions/remove_action/ To remove a hook, the $function_to_remove … Read more

Categories post-meta Tags actions, metabox, post-meta

How to save custom made object in an array in a post meta field

Arrays and objects get automatically serialized/unserialized because they are php data types being stored as strings by MySQL. If you save array with update_post_meta you don’t need to unserialize the returning value get_post_meta, function will do it for you. Easier to look at update_post_meta function’s source code. It calls update_metadata function where you can see … Read more

Categories functions Tags functions, oop, post-meta

How to display Author Profile based on Custom field value

You have to use meta query. $query = new WP_Query( array( ‘meta_key’ => ‘coauthor’ ) ); Later, you can loop through this query.

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

How to get all the related ids without array?

If you need the ids separated by coma you can get them from the array you have: $listids = implode ( “,” , $postids ); In any case, please provide more info or code about what you need

Categories post-meta Tags post-meta, wpdb

Auto save title as custom meta field value

Well because your code seems like to be bugy/not full – i wrote my code. This will add one meta box with one text field in post (you can change it to be added in your custom post_type)- Post title. Also i had to use QUERY to update/add title, because i can not find any … Read more

Categories post-meta Tags post-meta, save-post, title

Applying if (get_post_meta) to new shortcode

First up the display_ad function should have a parameter $content that contains the post’s content upto the point where the shortcode is placed. So you concatenate that $content with your advertisement image before returning it. Second what’s wrong with : if( empty( get_post_meta( $post->ID, ‘wpcf-display-ad’, true ) ) ) { return $content; } else { … Read more

Categories shortcode Tags post-meta, shortcode
Older posts
Newer posts
← Previous Page1 … Page9 Page10 Page11 … 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