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

add unique string as custom-field to every post

There is a simplier way to do what you want to: function add_unique_post_identifier( $post_id ) { $unique_post_identifier = get_post_meta($post_id, ‘unique_post_identifier’, true); // do nothing if post type is not ‘post’ or identifier is already set if (‘post’ != get_post_type( ( $post_id ) ) || !empty($unique_post_identifier) ) return; $generated_id = uniqid(); update_post_meta($post_id, ‘unique_post_identifier’, $generated_id); } // … Read more

Categories post-meta Tags post-meta

Remove last character in get_post_meta

This is more of a PHP question then a WordPress question. If you want to remove punctuation marks like (.,-;:) you can try this recursive version: $s = get_post_meta( $post->ID, ‘one_line_summary’, TRUE ); if( function_exists( ‘remove_punctuation_marks’ ) ) $s = remove_punctuation_marks( $s ); with /** * Remove punctuation marks (.,-;:) if they’re the last characters … Read more

Categories post-meta Tags post-meta

Difficultly changing date format in post meta value

Oh my. You’re doing some freaky stuff there. 🙂 Please try it like this: $args = array( ‘posts_per_page’ => -1, ‘post_type’=> ‘match_report’, ); $query = new WP_Query($args); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $matchdate = get_post_meta(get_the_ID(), ‘report_date’, true); $new_matchdate = DateTime::createFromFormat(‘d-m-Y’, $matchdate); update_post_meta(get_the_ID(), ‘report_date’, $new_matchdate->format(‘Y-m-d’)); } wp_reset_postdata(); } // EDIT If you have problems … Read more

Categories post-meta Tags post-meta

Sort Posts By Custom Field Date?

Use meta_value instead of meta_value_num <?php $course = new wp_query( array ( ‘posts_per_page’ => ’10’ , ‘post_type’ => ‘course’, ‘orderby’ => ‘meta_value’, ‘meta_key’ => ‘course_date’, ‘order’ => ‘DESC’ ) ); ?>

Categories post-meta Tags date, post-meta, post-type

esc_attr on get_post_meta [closed]

The best practice in the WordPress world is to “escape late” i.e. at the point of output. While the two examples are effectively the same, the first one would be more effective if that code is ever refactored and the value of $portf_icon changes between where it’s first assigned & where it’s output.

Categories post-meta Tags post-meta, sanitization

Can A Post Meta Field Store multiple values that are not in an array?

Meta data keys do not have to be unique, you can have multiple rows of the same key, each containing singular values. If you use get_post_meta to fetch a key and don’t set the 3rd argument to true, the function gets all the individual values and returns them as an array, which is not the … Read more

Categories post-meta Tags array, post-meta, sanitization

String taken from database table post_meta is showing HTML tags on Frontend

Use the htmlspecialchars() function in PHP in the templates, because the wordpress-api does htmlspecialchars on import. The following code works fine <?php print htmlspecialchars_decode(get_post_meta($post->ID, ‘field_name’, true)); ?>

Categories post-meta Tags post-meta

How to remove Date from Meta Description on SERP?

If anyone else encounters this, check your source code and try and find the date in question to see where it’s being inputted, Googlebot normally finds these dates there. It turned out the Googlebot was picking up a date in the footer of my site, via the WordPress Latest Posts Widget, where I had selected … Read more

Categories post-meta Tags date, genesis-theme-framework, plugin-wp-seo-yoast, post-meta, seo

Reset/delete post views meta/custom field after X hours or minutes or seconds

Your code for scheduling event isn’t correct, here is the correct one: function hits_set_zero_schedule() { if ( ! wp_next_scheduled( ‘hits_set_to_zero’) ) wp_schedule_event( time(), ‘daily’, ‘hits_set_zero’ ); } add_action( ‘wp’, ‘hits_set_zero_schedule’ ); function hits_set_zero_func() { delete_post_meta( $post_id, ‘post_views_count’, true ); } add_action( ‘hits_set_zero’, ‘hits_set_zero_func’ ); Also, you can define intervals otherwise than daily by adding a … Read more

Categories post-meta Tags post-meta, wp-cron

Mass removing CSS from 1,700 post [closed]

You can remove them by replacing the line( .alignleft { float: left; } ) with empty space in database ( but you should avoid using SQL query). Make sure you have back up before trying anything. There is a php script which i used for replacing my loclahost url to live site url while migrating … Read more

Categories post-meta Tags blogger, post-editor, post-meta
Older posts
Newer posts
← Previous Page1 … Page28 Page29 Page30 … 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
  • 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
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