Currently i’m using get_posts to get the 10 latest posts but the problem that i dont get all information for example i cant access the post category or author.
i would like to use WP_Query with get_the_title(), get_the_post_thumbnail, get_permalink() etc. the results have to be stored into variables.

my setup:

$latest_posts = get_posts( array(
        'category_name'  => 'Allgemein',
            'posts_per_page' => 10,
                "orderby"        => "date",
                    "order"          => "DESC"
    ) );




    // Post 1 -- Category: Allgemein
    if ( isset( $latest_posts[0] ) ) {  // array zero-based index.
        // $post1_category = $latest_posts[0]->post_category;
        $post1_date = $latest_posts[0]->post_date;
        $post1_title = $latest_posts[0]->post_title;
        // $post1_tags = $latest_posts[0]->post_tags;
        $post1_author = $latest_posts[0]->post_author;
        $post1_content = $latest_posts[0]->post_content;
        $post1_thumbnail = $latest_posts[0]->get_the_post_thumbnail;
    }

    // Post 2 -- Category: Allgemein
    if ( isset( $latest_posts[1] ) ) {
        // $post2_category = $latest_posts[1]->post_category;
        $post2_date = $latest_posts[1]->post_date;
        $post2_title = $latest_posts[1]->post_title;
        // $post2_tags = $latest_posts[1]->post_tags;
        $post2_author = $latest_posts[1]->post_author;
        $post2_content = $latest_posts[1]->post_content;
        $post2_thumbnail = $latest_posts[1]->get_the_post_thumbnail;
    }

    Post3-10
    ....

and in my index.php:

<div class="title">
   <?php echo $post1_title?>
</div>

Thanks in advance, i appreciate any help you can provide.

Read more here: WordPress wp_query get result into variables


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: