I’ve been looking at the classes WP_Comment_Query and WP_Meta_Query but to be honest, I can’t figure out how to use them together. I want to query the database for comments where wp_posts::post_author == X
and wp_comments::comment_post_id == wp_posts::post_id
. Could anybody give an example of usage?
Since SQL is not my thing, and this next question is not really WP related, but how would a SQL query be built to handle 2 tables?
When it comes to retrieve posts, it’s supposed to call WP_Query.
WP_Query
has an argument calledmeta_query
but it doesn’t havecomment_query
.So it might need a trick to achieve what you want,
Please note that, the $args may need more values such as post_status and posts_per_page. I’m just giving you a general idea here.
It’ll generate two SQL queries:
The second SQL query will retrieve posts by posts IDs which returned from 1st SQL.
I would recommend using custom SQL query for your task