1

I am having some trouble pulling multiple custom post types from a Custom Wordpress Query. The reason I am creating a custom Wordpress query rather than using query_posts or WP_query is because I am sorting my posts based on information added by a voting plugin, and have to join that plugin's table, so the built-in queries are not an option.

My question is how can I include multiple custom post types in the same query? At present, my query looks like the following:

$query = "
    SELECT wposts.*
    FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
    WHERE wposts.ID         = wpostmeta.post_id
    AND wposts.post_status  = 'publish'
    AND wposts.post_type    = 'TWO_POST_TYPES'
    AND post_date       >= '$startdate'
    AND post_date       <= '$enddate'
    GROUP BY wposts.ID
    ";

I am trying to put two different custom post types into the wposts.post_type part, which we can call type1 and type2. What I have already tried is the following, with no luck:

  1. array('type1', 'type2')
  2. 'type1, type2'

I have also tried passing both of these as variables in the query, but also no luck. Would anybody be able to give me a hand?

1 Answer 1

2

Do you mean this?

AND wposts.post_type IN ('type1', 'type2')

which actually means:

AND ( wposts.post_type = 'type1'
   OR wposts.post_type = 'type2'
    )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.