Right now I have several images attached to my page, but I only want four of them to display in a slideshow, and then the other ones are referenced within the page's visual/html box. The problem is currently all my images attached to the page have a post type of "attachment", and this code iterates through all of them:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post();

    $args = array(
     'post_type' => 'attachment',
     'numberposts' => -1,
     'orderby'=> 'menu_order',
     'order' => 'ASC',
     'post_mime_type' => 'image',
     'post_status' => null,
     'post_parent' => $post->ID

     $attachments = get_posts( $args );
      if ( $attachments ) {
       foreach ( $attachments as $attachment ) {
        echo wp_get_attachment_image($attachment->ID , 'full','',array('rel' => $attachment->post_name));
    endwhile; endif; ?>

My question is how can I distinguish the attachments so that it only queries some of them? For example, I tried adding the post_name attribute to the $args array but that didn't do anything.

Second, when I add img tag to the visual/html content editor, and then I add a src attribute, and then I go into the visual content editor, I want a non-programmer to click on the img box, which prompts them to edit the image, and then under source it is requiring them to add the full url path, and I dont think that's intutive to a non-programmer. Is there an easier way for them to add image via content editor?

  • Your second question doesn't make much sense, and it could even deserve a completely new Question. A snapshot would be useful...
    – brasofilo
    Commented Jun 30, 2012 at 0:54
  • Any progress? Was one of the answers helpful? Do you still miss something?
    – fuxia
    Commented Oct 6, 2012 at 22:42

2 Answers 2


Every file that is uploaded in WordPress is an Attachment, which is a kind of post ('post_type' => 'attachment').

When the file is uploaded inside a Post or Page, it is attached to that particular post/page ('post_parent' => $post->ID). enter image description here

I can think of a solution that doesn't involves any particular coding:

  • you simply have to put an order in your gallery images ('orderby'=> 'menu_order') and set the number of posts (of the attachment type) to be grabbed as four ('numberposts' => 4). enter image description here image source

Add a meta box to the attachment edit screen and use get_post_meta() to separate the images you want from the rest.

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.