I am making a custom WP_Query and I need to come up with a SQL query that gets the posts IDs from X categories and Y authors. Then merge those IDs and put them in an array.

I only need to figure out the SQL query. Everything else, I got it.

I have looked everywhere for this but no one has been able to help me. Please help me out!!

1 Answer 1


Not the best solution :P but this could help you:

    wp_posts p,
    wp_term_relationships r,
    wp_term_taxonomy tt,
    wp_terms t
    p.post_author in (1, 2, 3)
        and r.object_id = p.ID
        and tt.term_taxonomy_id = r.term_taxonomy_id
        and tt.taxonomy = 'category'
        and tt.term_id = t.term_id
        and t.term_id in (1, 2, 3);
  • Thanks but I am lookning for something like: SELECT distinct posts id FROM posts WHERE category id AND user id
    – Gixty
    Mar 10, 2014 at 20:07
  • Great, i will try that when i get home.
    – Gixty
    Mar 10, 2014 at 20:15
  • Ok :) codex.wordpress.org/Class_Reference/WP_Query#Parameters i think this is even better to solve your problem.
    – Splitt3r
    Mar 10, 2014 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.