title: How to get first and last postdata from custom post type in wordpress?
body: <p>In the wordpress theme I have created custom  post type. In this custom post type images are attached using image upload metabox field. For this I can create any number of posts( images). </p>
  
  <p>At the front end ,inside my main template I got those images in loop using following wordpress functon:</p>
  
  <pre><code>    &lt;?php
  
      global $post;
      $args = array(
      'post_type' =&gt;'Imagespost',
      'numberposts' =&gt; -1,
      'order' =&gt; 'ASC' );
  
      $image_posts = get_posts($args); ?&gt;
  
      &lt;?php
          if($image_posts) { ?&gt;
  
        &lt;div id="bigImages"&gt;
        &lt;ul class ="image-list"&gt;
  
             &lt;?php
  
              foreach($image_posts as $post) : setup_postdata($post);
  
               // get attached image URL from image upload metabox field.
               $full_image = get_post_meta($post-&gt;ID, 'my_image', true);
  
             echo  '&lt;a href=" ' . $full_image . '" class="playlist-btn"&gt;';
            ?&gt;
                &lt;?php endforeach;?&gt;
  
              &lt;/ul&gt;
         &lt;/div&gt;
  
   &lt;?php wp_reset_postdata(); ?&gt;
   &lt;?php } ?&gt;
  </code></pre>
  
  <p>In this way I am storing each attached image as $full_image inside loop and using it as href attribute for further display . same way I want to store only first image or last image as a variable depends if <code>ORDER: as ascending (ASC) or descending (DESC).</code> How can I grab only the data from first or last post from custom post type?</p>