Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7898621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:28:57+00:00 2026-06-03T08:28:57+00:00

I know you guys going to say this might be possible duplicate to PHP

  • 0

I know you guys going to say this might be possible duplicate to PHP get index of last inserted item in array

But I’ve tried and not succeed to get my function work and I’m trying to figure it out why.

I’ve a function which will grab the thumbnail attachment from the content of WordPress post.

The code working fine with a post that have only one image, but if there are more than one image in the post it will display the first image correctly from the array, but I don’t know why it stores the image in reverse. Meaning the first image of the post stored last and the last store first. I’m geussing this is maybe how the media function of WordPress work.

Anyway I just need to get the last inserted data from function even if it has one or more than one image stored in the array

// Get Image Attachments
function sa_get_image($postid=0, $size='thumbnail') { 
    if ($postid<1)
    $postid = get_the_ID();
    $thumb = get_post_meta($postid, "thumb", TRUE); 
    if ($thumb != null or $thumb != '') {
        echo $thumb;
    }
    elseif ($images = get_children(array( 
        'post_parent' => $postid,
        'post_type' => 'attachment',
        'numberposts' => '1',
        'post_mime_type' => 'image', )))
        foreach($images as $image) {
            $thumbnail=wp_get_attachment_image_src($image->ID, $size);
            ?>
    <?php echo $thumbnail[0]; ?> // here is the problem where the image display.
    <?php }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:28:59+00:00Added an answer on June 3, 2026 at 8:28 am

    There is an easier method to my solution and here is how we can get the last from the array.

    Simply just add this to the array area.

    'orderby' => 'menu_order',
    'order' => 'ASC', //If reverse use DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Guys, I know this is going to turn out to be a simple answer,
Hi guys anyone know what the helll is going on here? ERROR SNIPPET: Loading
Hi guys i am going to make a android game. i wanna know that
guys I know this question is very basic but I've met in few publications
Guys I know this question is silly but just to make sure: Having in
Hey guys - I know this is not a strictly programming question but I'm
Right, I know I am totally going to look an idiot with this one,
So I know that if you guys don't like my question you are going
hey guys, i know it's not the best way of doing this but the
You guys know in Pastebin how according to the selected language, the code is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.