How to retrieve a value from get_posts()? [closed]

Each post is an object, which changes the syntax you need to use to access the post name:

$arr = get_posts();
$arr = array_reverse($arr);
foreach ($arr as $post) {
    echo $post->post_name;
    echo "<br/>";
}

As a side point, a slightly easier (and computationally more efficient) way to get your posts in reverse order is to use this instead of array_reverse()

$arr = get_posts(array('order'=>'ASC'));

More fun things you can do with get_posts()’s arguments can be found here and here.

Leave a Comment