WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some post ids in an ID array, like:

$ids = array(20,34,65,126) ;

There is many custom post types in my project, these ids are related to different post types, but I dont know which id is related to which post type in that condition. In another word, I need to do something like this:

$posts = my_get_posts(
   'ids' => array(20,34,65,126),
   'post_type' => 'product',
) ;

That function has to be eliminate ids which is not a producy.

How to do this?

share|improve this question
up vote 1 down vote accepted

I am assuming this-- "That function has to be eliminate ids which is not a producy"-- means "I only want to pull the post associated with the ID if that post is a product". In that case a simple query should do it:

$pqry = new WP_Query(
    'fields' => 'ids', // if you only want the Post IDs
    'post_type' => 'product',
    'post__in' => array(20,34,65,126)



share|improve this answer
That was very short and complex usage like a tequila shot, Thank you! – Digerkam Feb 25 '13 at 16:01
Do I have to use WP_Query? "get_posts" seems not work – Digerkam Feb 25 '13 at 18:01
I prefer WP_Query. get_posts should probably work but the syntax may be different. I'd have to look it up to be sure, since I virtually never use it. – s_ha_dum Feb 25 '13 at 18:04
It worked then, but the result is weird, it returns the array of ids which from selected post type, not posts :) – Digerkam Feb 25 '13 at 18:48
Is that not what you asked for? – s_ha_dum Feb 25 '13 at 19:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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