There might be other causes to the issue in question, but one issue I noticed in your code is that because you are looping through a custom WP_Query
instance, i.e. $loop
, then you need to use $loop->the_post()
instead of just the_post()
:
while ( $loop->have_posts() ) {
$loop->the_post();
the_title();
}
And you could see that I simply called the_title()
and not doing echo get_the_title()
, so you should also do the same.