如何根据类别名称从wordpress数据库中选择所有帖子?

First off, I know this question has been asked many times before and I found quite a few of them on this site and Google.

example: How does Wordpress link posts to categories in its database?

However, I can't really understand how to find all the posts based on their category names from wordpress database.

Example: I have a category name called 'restaurants'.

And I have a few posts under that category.

What is the correct query for this?

also, in the link above, I noticed that the provided answer mentions that the wordpress database might change, so what is the best query to use to make sure these changes doesn't break my code?

Thanks in advance.

EDIT:

Here is one example that i tried which doesn't work.

<?php 

require_once(ABSPATH . 'wp-config.php');
$connection = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysqli_select_db($connection, DB_NAME);

$custom_query = new WP_Query('cat=9'); //your category id 
while($custom_query->have_posts()) : $custom_query->the_post(); ?>

    //loop items go here

<?php endwhile; ?>
<?php wp_reset_postdata(); // reset the query ?>

EDIT 2:

I tried this code which doesn't do anything. Just a blank page:

<?php

require_once('../wp-config.php');
$connection = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysqli_select_db($connection, DB_NAME);



$args=array(
'post_type' => 'post',
'post_status' => 'publish',
'category_name' => 'restaurants');

$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post();
    echo '<div class="Entradas">'.get_the_title().'</div>';
endwhile;
}
wp_reset_query();



?>

This worked fine:

  $myposts = get_posts(array(
  'showposts' => -1, //add -1 if you want to show all posts
  'post_type' => 'offer',
  'tax_query' => array(
              array(
                    'taxonomy' => 'offer_cat',
                    'field' => 'slug',
                    'terms' => 'restaurants' //pass your term name here
                      )
                    ))
                   );

    foreach ($myposts as $mypost) {
    // echo $mypost->post_title . '<br/>';
    // echo $mypost->post_content . '<br/>';
    // echo  $mypost->ID . '<br/><br/>';
    echo '<li class="faq"> <p class="title"><a href="' . get_permalink($mypost) . '">' . $mypost->post_title . '</a></p></li>';} 

I hope it helps others.