I’m developing a responsive WordPress theme and instead of using frameworks, I’ve created one my own.
I’m trying NOT to repeat myself (meaning, I don’t want to write extra markup all the time), so I’m generating the HTML that comes before the .grid-unit div
element with a fluid_grid
PHP function that takes a function as a first parameter.
I’m pulling some custom post types using WP_Query
:
function slider_template() {
// Query Arguments
$args = array(
'post_type' => 'slides',
'posts_per_page' => 10
);
// The Query
$the_query = new WP_Query( $args );
// Check if the Query returns any posts
if ( $the_query->have_posts() ) {
// I'm passing an anonymous function here, that needs to be called later on
fluid_grid( function() {
?>
// Here goes the markup that should be printed out later
<?php
} ); // Close the anonymous function, and end the fluid_grid function.
} // End of the if statement
} // End of slider_template function
After visiting the page, I’m getting the following error:
Fatal error: Call to a member function have_posts() on null in ...
I’ve tried making the $the_query
global, but ended up with the same result ($the_query
is still null).
Is it possible to get $the_query
variable working inside the anonymous function? If so, how?