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 obtain a group of post meta and assign each meta to other variables?

foreach ($boxes as $data) { $project[$data] = get_post_meta($post->ID, $data, true); } $item_a = $project[‘height’]; $item_b = $project[‘width’];

Categories post-meta Tags post-meta

Query posts WITHOUT a custom meta field

You have to do a join or a subquery: $querystr = ” SELECT $wpdb->posts.ID FROM $wpdb->posts WHERE $wpdb->posts.post_type=”post” AND $wpdb->posts.post_date < NOW() AND $wpdb->posts.ID NOT IN ( SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = ‘_social_’ ) ORDER BY $wpdb->posts.score DESC LIMIT 1; “;

Categories post-meta Tags post-meta, query

Delete posts based on post meta data

DELETE wp_posts FROM wp_posts INNER JOIN wp_postmeta ON wp_postmeta.post_id = wp_posts.ID WHERE (wp_postmeta.meta_key = ‘InternalOnly’ AND wp_postmeta.meta_value IS NOT NULL);

Categories post-meta Tags post-meta

Sort custom posts in archive by multiple values: date AND meta key

You have syntax error in query arguments: ‘orderyby’.

Categories post-meta Tags custom-post-type-archives, order, plugin-wp-pagenavi, post-meta, sort

get meta value from page query

When you are in your while loop, the parent query is already finished. So fetch the post meta value with get_post_meta(): $template = get_post_meta( get_the_ID(), ‘_wp_page_template’, TRUE );

Categories post-meta Tags 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
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
  • 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