WP Query Leads to 502 Bad Gateway (Timeout Because Query Takes Too Long)

Why does this simple query break my site and lead to the following error:

502 Bad Gateway

I am using the category slug and yes I have exactly one post of this category. It is embedded in the header template part of a third-party theme.

function bambam(){
$args = array(
‘category_name’ => ‘breaking-news’,
‘post_date’ => ‘DESC’,
‘posts_per_page’ => 1);

$the_query = new WP_Query( $args );

if ( $the_query->have_posts() ) {
echo ‘<div class=”breaking-news”>’;
while ( $the_query->have_posts() ) {
echo ‘<h1>’ . get_the_title() . ‘</h1>’;
}
echo ‘</div>’;
/* Restore original Post Data */
wp_reset_postdata();
} else {
// no posts found
}
}
bambam();

Read more here:: WP Query Leads to 502 Bad Gateway (Timeout Because Query Takes Too Long)

Leave a Reply

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