How can I properly loop through an array gotten from my wordpress database and display it to my site


I am trying to display some posts information from my database on my live site. I have done the query correctly because I can view the items on the live site. But I need to take three items to display. The post title, the post content which houses the images, and the post id which links to the posts. I seem to have written it correctly but it does not do anything.

This is the code

    global $wpdb;               
    $results = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE `post_type`='post' AND `post_status` = 'publish' LIMIT    20" );

  foreach ($results) {
  echo "<div class="card">
            <div class="img">
             <img src="{post_content}" alt="">
            <div class="info">
   //echo "<pre>";print_r($results);echo"</pre>";

I am quite new to wordpress and PHP in general.

Chinomso Johnson 4 months 0 Answers 12 views 0

Leave an answer