I have following array:
array (12,15,21,32,33);
And then I use the following query to get the posts (of the above of IDs):
$the_query = new WP_Query( array("post__in"=>$ids_array) ); // edited
while($the_query->have_posts())
{
$the_query->the_post(); // added on edit, but still does not work
the_title()."<br />";
}
But I get nothing, no error and no interruption. I have checked the IDs and they are correct.
EDIT: I have put this query at the end of a module which is loaded into the footer. I don’t know if it is important or not:
You forgot to add
while ( $the_query->have_posts() ) : $the_query->the_post();
.You are just checking to see if you have posts, but doing nothing further
EDIT
I think the underlying problem here is not this custom query, as this custom query works. It seems from your comments that you are using another custom query on the same page.
I don’t know what the code of the first query looks like, but here are some troubleshooting points you need to go and have a look at
Most probably you did not reset the postdata on your first query. This will break your second query.
wp_reset_postdata
is extremely important when you are running custom queries withWP_Query
and withget_posts
. Check that you have usedwp_reset_postdata
after your first instance ofWP_Query
. Your first query should be in the same format as the one in my answerYou should use different variables for each instance of
WP_Query
. For example$variable1 = new WP_Query( YOUR ARGUMENTS )
for first instance and$variable2 = new WP_Query( YOUR ARGUMENTS )
for your second instance