My shortcode always uses the default value for the single attribute, reviewstoshow, instead of the incoming attribute value. The incoming value has the correct number (per the second half of the dump included below) but the $numberofreviewstoshow var is always set to the default value (6).
Here is the shortcode being used:
[tdp_random_reviews reviewstoshow="8"]
This is the shortcode code:
add_shortcode( 'tdp_random_reviews', 'show_tdp_random_reviews' );
function show_tdp_random_reviews($atts) {
$a = shortcode_atts(
array(
'reviewstoshow' => '6'
),
$atts
);
var_dump($a);
var_dump($atts);
$numberofreviewstoshow = $a['reviewstoshow'];
<snip>
}
Here is the output from the two var_dump() lines:
array(1) { ["reviewstoshow"]=> string(1) "6" }
array(1) { [0]=> string(30) "reviewstoshow="8"" }
Can you tell me where my mistake is? Thanks!
var_dump
() of$numberofreviewstoshow
? It looks right -$a['attributename']
. You might also want to double-check types (string vs. integer) and quotes (smart vs. plain) if that's not giving you the value you expect.var_dump
should be outputting an array, not a string. Are you sure your shortcode itself is correct? You're not using weird quotes around the 8, or something? Because WP is not recognizing the parameter.