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

Clean up output added via wp_head()

You can remove some of the header stuff with the following. // remove unncessary header info function remove_header_info() { remove_action(‘wp_head’, ‘rsd_link’); remove_action(‘wp_head’, ‘wlwmanifest_link’); remove_action(‘wp_head’, ‘wp_generator’); remove_action(‘wp_head’, ‘start_post_rel_link’); remove_action(‘wp_head’, ‘index_rel_link’); remove_action(‘wp_head’, ‘adjacent_posts_rel_link’); } add_action(‘init’, ‘remove_header_info’); The default installation does not include stuff like meta keywords, so that is either a theme or plugin that you are … Read more

Categories post-meta Tags functions, headers, post-meta, seo

How do I save each option in a multiple select menu as it’s own meta_key + meta_value pair?

Try this inside save_post but please note the code is not tested $old = get_post_meta($post_id, ‘products’); $new = isset ( $_POST[‘products’] ) ? $_POST[‘products’] : array(); if ( empty ($new) ) { // no products selected: completely delete alla meta values for the post delete_post_meta($post_id, ‘products’); } else { $already = array(); if ( ! … Read more

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

Setting post meta data to random value during post status transition / on publish

Slight change in your code, function wpse_custom_field_on_publish( $new, $old, $post ) { // Only run on “from X > to publish”-transitions if ( $new === ‘publish’ && $old !== ‘publish’) { $page_views = get_post_meta( $post->ID, ‘post_views_count’, true ); // Only set ‘post_views_count’ post meta value if there is none so far if ( empty( $page_views … Read more

Categories posts Tags post-meta, post-status, posts

WP REST API “rest_no_route” when trying to update meta

Here is what I have learned about the WP REST API: It is a mess of undocumented and unfinished code with great promise but frustratingly little clarity. That said, I have a workaround that I will post here, hoping it is useful to others in a similar pickle to me: I just found that I … Read more

Categories post-meta Tags post-meta, rest-api

How to count post meta key values for all posts in database

You have a structural problem with your data. Serialized data in the database is terrible if you need to search over pieces of that serialized data. There is no reliable, efficient, and certainly no easy, SQL query to search over serialized data. “serialization” is a PHP mechanism. It isn’t SQL. To the database that is … Read more

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

update_post_meta() not working in save_post

You aren’t retrieving the saved data and populating the form. function swpd_render_info_fields() { ?> <label for=”swpd_comany_addr”>Company Address</label> <input type=”text” name=”swpd_company_addr” id=”swpd_company_addr” /> <?php } There is nothing in that function that would insert your saved data. You just write a blank form every time. You need to be conditionally populating the input value. function swpd_render_info_fields($post) … Read more

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

Documentation for post meta

There is no official documented list of all possible post meta keys in core. The closest I could for anything unofficial was this answer on Stack Exchange: You probably don’t want to use the following post meta keys: _thumbnail_id – Used to store the featured image ID _edit_last – Used by the Heartbeat API _edit_lock … Read more

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

Compare 3 custom fields and sort by oldest

While the query you describe is not impossible in SQL, it is not going to be very efficient as the query would have to evaluate every row in the table matching those keys, and then sort based on the result of the calculation. You are better saving a fourth value and sorting on that, as … Read more

Categories custom-post-types Tags custom-post-type-archives, custom-post-types, order, post-meta

Is it possible to sort the post based on a custom field?

Yes, You can call action “pre_get_posts”. add_action(‘pre_get_posts’,’search_filter’); You can add parameter : $args = array( ‘post_status’ => ‘publish’, ‘posts_per_page’ => 6, ‘paged’ => $paged, ‘meta_key’ => ‘event_date’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’ ); You can use above parameter e.g. : function search_filter($query){ if ( !is_admin() && $query->is_main_query() ) { $query->set(‘post_status’, ‘publish’); $query->set(‘meta_key’, ‘event_date’); $query->set(‘orderby’, … Read more

Categories custom-taxonomy Tags custom-field, custom-taxonomy, loop, post-meta

How to get meta value in wp_attachment_metadata

There are two methods: get_post_meta() $attachment_meta = get_post_meta( $post->ID, ‘_wp_attachment_meta’, true ); Will return an array(): $width = $attachment_meta[‘width’]; That true as the third parameter is especially important in this case, since the metadata being queried is a serialized array. You need to return it as single, or you’re going to get an array returned, … Read more

Categories post-meta Tags attachments, images, post-meta
Older posts
Newer posts
← Previous Page1 … Page181 Page182 Page183 … 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