For some reason the WP_Query instance in my shortcode function won't take the query attribute sent from the shortcode. The shortcode is like this: [postlist query="post_type=any&posts_per_page=5" style="list"]
Here's the code.
function hey_query_shortcode( $atts ) {
extract( shortcode_atts( array(
'query' => '',
'style' => ''
), $atts ) );
ob_start();
$the_query = new WP_Query( $query );
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<h2>I know $style is set bc it shows up here: <?php echo $style; ?></h2>
<h2>I know $query is set bc it shows up here: <?php echo $query; ?></h2>
<?php
endwhile;
echo '<hr>';
wp_reset_postdata();
$list = ob_get_clean();
return $list;
}
add_shortcode( 'postlist', 'hey_query_shortcode' );
Any idea what is going on here? $query echoes out fine but for some reason it doesn't affect the WP_Query query.