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

Based on this previous WPSE question:

I tried a limit of 10 files, but it did not work:

if ( count( get_posts( "post_type=attachment&post_parent={$post_id}" ) ) > 10 )

How to limit it to 10 images?


share|improve this question

here you go:

get_posts(array('post_type'=>'attachment', 'numberposts' => 10, 'post_parent' => $post_id));

this will return you upto 10 posts.

share|improve this answer
if you want to get only published files, you should use 'post_status' => 'published' too. – HungryCoder Jun 18 '12 at 14:10
I want to limit to only upload 10 images per post... – Antonio Jun 18 '12 at 19:47

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.