[Plugin: Posts 2 Posts] Custom query, but still using 'connected to' query var
-
Hey there, thanks for the wicked plugin.
I just got asked to add an additional sorting feature to the loop for a page drawing on a large number of posts. Although the default loop doesn’t use the ‘connected_to’ query var, users have the option of filtering the initial loop results using various ‘connected_to’ values. However, now I need to group all the posts with featured images first, followed by the posts without featured images.
I figured out a MySQL select statement that will do this, but how would I pass a custom SQL query, but still be able to take advantage of P2P?
Here is the query:
( select posts1.ID, posts1.post_name, posts1.post_title, meta1.meta_key, meta1.meta_value from wp_posts as posts1, wp_postmeta as meta1 where posts1.ID = meta1.post_id AND meta1.meta_key = '_thumbnail_id' AND posts1.post_type = 'athletes' AND posts1.post_status = 'publish' group by posts1.ID ) union ( select DISTINCT posts2.ID, posts2.post_name, posts2.post_title, meta2.meta_key, meta2.meta_value from wp_posts as posts2, wp_postmeta as meta2 WHERE posts2.post_type = 'athletes' AND posts2.post_status = 'publish' AND meta2.post_id = posts2.ID AND meta_key = 'born' group by posts2.ID )
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘[Plugin: Posts 2 Posts] Custom query, but still using 'connected to' query var’ is closed to new replies.