WP_Query in shortcode ignoring passed value
Been trying to get this to work for hours. No matter what I do WP uses the default value and ignores values passed into the function.
// Add Shortcode
function ima_featured_member( $atts ) {
// Attributes
$attributes = shortcode_atts(
array(
'numb' => '1',
),
$atts,
'featured'
);
$dirloop = new WP_Query( array(
'post_type' => 'member',
'post_status' => 'publish',
'posts_per_page' => $attributes['numb'],
'orderby' => 'title',
'order' => 'ASC',
'meta_query' => array (
'relation' => 'AND',
array (
'key' => 'elc_member_featured',
'value' => '1',
'compare' => '=='
)
)
));
if ($dirloop->have_posts())
{
$output = "\n";
while ( $dirloop->have_posts() ) : $dirloop->the_post();
$output .= ''.get_the_title().'';
endwhile;
$output .= "\n";
}
else
{
$output = "nothing";
}
wp_reset_postdata();
return $output;
}
add_shortcode( 'featured', 'ima_featured_member' );
[featured = '2'] doesn't pass. No errors, no warnings, just doesn't work. Any help or insite is much appreciated.
The shortcode_atts
portion of the function seems fine.
But the correct way to call the shortcode with the parameter numb
being 2
would be:
[featured numb='2']
and not
[featured = '2']