Custom wp_query inside a conditional stament inside a template part doesn’t work: why?

You have assigned the queries result inside the first condition. So the values assigned to this variable “cm_offerta_post_figli” won’t be accessible inside the second elseif condition. Please put the below code on the top of First condition. It will work. <?php $cm_offerta_post_figli = new WP_Query( array( ‘post_type’ => ‘cm_offerta’, ‘post_parent’ => get_the_ID(), ‘order’ => ‘ASC’, … Read more