Using a custom WP_Query with get_template_part loop

You will either need to globalize $books (if you want to stick to get_template_part() ) or use

require( locate_template( 'loop-books.php' ) );

instead of get_template_part( 'loop', 'books' );. This issue is caused by $books in loop-books.php being defined only in the scope of get_template_part().

Leave a Comment