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

Have lots of meta for posts, is it better to get at all at once or each individually

Assuming you’re retrieving the posts using a standard WP_Query in some manner, then the postmeta data is automatically retrieved for all the relevant posts and cached in memory. When you later call get_post_meta, the data is simply returned from here. So honestly, it doesn’t make any significant difference which approach you take. The get_post_meta function … Read more

Categories post-meta Tags post-meta

Unfiltered html with update_post_meta

Do you really want your members to be able to insert unfiltered html in the database? By default, it’s not allowed as a security measure to protect your installation. You could allow it by adjusting kses filters. Or by-pass the filters via a custom sql query.

Categories post-meta Tags buddypress, post-meta

mass delete posts based on metadata

from my comment above: I can do this now with two separate queries, but it would be nice to be able to do it in one. Still, this is progress. The first query is like this: DELETE wp FROM wp_posts wp LEFT JOIN wp_postmeta pm ON pm.post_id = wp.ID WHERE pm.meta_key = ‘state’ AND pm.meta_value … Read more

Categories post-meta Tags post-meta, sql

How to display sql query fired by posts_where

The quick and dirty way is to put var_dump($wp_query->request) (or whatever you’ve named the WP_Query object if you’ve created a new one) on the page the query runs on and after it runs. You can also add define(‘SAVEQUERIES’, true); to wp-config.php to save the queries for analysis. You can read the queries something like this … Read more

Categories post-meta Tags post-meta

How do I insert a new meta key / value pair, but only if another meta key is present?

There’s no need to do this via raw SQL. Make use of the WordPress core functions get_post_meta and update_post_meta. Use them like so: $existing = get_post_meta( $post_id, ‘existingkey’, true ); if ( ! empty( $existing ) ) { update_post_meta( $post_id, ‘newkey’, ‘newvalue’ ); } Done.

Categories post-meta Tags post-meta, sql

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
Older posts
Newer posts
← Previous Page1 … Page27 Page28 Page29 … 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