Show posts in WordPress … probably the best option!

$query = [
    'post_type' => 'post',
    'post_status' => 'publish',
    'orderby' => 'date',
    'order' => 'DESC',
    'posts_per_page' => -1,
    'cat' => 1,
];

$posts = get_posts($query);

foreach ($posts as $post) {
    setup_postdata($post);
    
    the_title();
    the_content('', false);
}

wp_reset_postdata();

Filter by taxonomy

If you want to filter by taxonomy, you can add the following code before passing the query variable to get_posts.

$query['tax_query'] = [
    [
        'taxonomy' => 'my_custom_taxonomy',
        'field' => 'term_id',
        'terms' => 1
    ]
];

Leave a Reply

Your email address will not be published. Required fields are marked *