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
$ids_array = array (12,15,21,32,33);
$the_query = new WP_Query( array('post__in'=>$ids_array) );
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><?php the_title(); ?></h2></br>
<?php
endwhile;
wp_reset_postdata();
endif;
?>
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 with WP_Query
and with get_posts
. Check that you have used wp_reset_postdata
after your first instance of WP_Query
. Your first query should be in the same format as the one in my answer
You 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