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’];
foreach ($boxes as $data) { $project[$data] = get_post_meta($post->ID, $data, true); } $item_a = $project[‘height’]; $item_b = $project[‘width’];
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; “;
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);
You have syntax error in query arguments: ‘orderyby’.
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 );
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
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.
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
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
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.