0
votes
2answers
65 views

Short of raw SQL, can I query for multiple attachment metadata that have a given array key?

With raw SQL through $wpdb, I believe that I could do something along the lines of this (untested): SELECT post_id, meta_value FROM postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value ...
1
vote
1answer
223 views

How to best delete orphan wp_postmeta

I'm in the middle of doing some fairly complex queries involving metadata from a custom post type. Unfortunately if any posts are deleted the metadata stays put which complicates matters as I am ...
0
votes
2answers
108 views

Which query method to use? (edit- wpdb syntax problems)

I am trying to create a query in order to get all the metadata from a custom post type named match_reports that is associated with a meta_key and meta_value in another custom post type named ...
0
votes
1answer
98 views

Adding an orderby filter, casting postmeta with multiple keys

I am using this filter to sort my query by a date field stored as text (legacy data) add_filter( 'posts_orderby', 'my_posts_orderby_date', 10, 2 ); function my_posts_orderby_date( $orderby, $query ) ...
0
votes
0answers
99 views

Retrieve post data via WPDB class

I'm trying to figure out doing a custom query using the $wpdb Object. I have custom type posts, event_posts, that have meta data, images, as well as event dates which are input in the post with the ...
1
vote
1answer
634 views

Select from wp_post and multiple meta_value from wp_postmeta

My lack of SQL skills has stopped me in my tracks here. I'm trying to select post_id, post_title and two postmeta values - the first has the meta_key of 'search_country' and the second a meta_key of ...
0
votes
1answer
39 views

Cache metadata for set of posts

I have a query that can only be done using straight SQL, but I need to loop through the returns as a set of posts. As I understand it, WP_Query automatically gets all the metadata for all the posts ...
0
votes
1answer
1k views

How to insert multiple postmeta values with one query?

I have a custom script/plugin I am using for myself that creates a post along with some postmeta information. Right now, I have multiple $wpdb->insert, but I would like to condense this down into ...
4
votes
1answer
361 views

What is the advantage of the wp_options design pattern?

As we all know, a design pattern that is used frequently in Wordpress' DB code is the idea of persisting data for a particular object (blog/post/comment), indexed with a particular name or key. We ...
1
vote
1answer
39 views

Get a row from a separate table by matching a posts meta_key to a tables ID column

I am trying to match a posts meta_key value to a separate tables column ID and call that row/array in the single-listing.php. I have a meta_key value that is called dot_number. The table is called ...
0
votes
1answer
112 views

Compare string with post id in wpdb and do stuff when match is found

I'm looking for some help tying in with the wpdb to compare and change certain values. I'm very novice with mysql handling so I really appreciate any help on this matter! What I want to do is to go ...
0
votes
1answer
803 views

wpdb->get_var - count author posts, meta value

In an author.php template, i count the author post in a custom post type with $wpdb->get_var, $post_author = $curauth->ID; //author id $count = $wpdb->get_var( "SELECT COUNT(*) FROM ...
1
vote
1answer
446 views

MySQL Query To Select Post By Postmeta

I have two custom post types, type1 and type2. Type2 posts have a postmeta called postID that is the ID number of a post in type1. When showing type1 in single.php I want a mysql query that selects ...
0
votes
2answers
173 views

How to query and update one colum in postmeta table?

I'm trying to make a popularity calculation for all posts, based on page view and date of creation. Initially, there's a default popularity value saved in postmeta. Every hour I want to recalculate ...
0
votes
2answers
1k views

How to test the outcome of a wpdb query?

I want to get all the data with the meta key of "project_id" from post meta table. I wrote a query, it should work in thoery, but I have no way to see what I get, and inject this query to my plugin ...
-1
votes
1answer
296 views

How to get all the related ids without array?

I want to get all the post ids when the post meta includes a key of "project_id". This function get the job down, but need refine: function get_all_ids(){ global $wpdb, $post; $meta_key1 = ...