admin管理员组文章数量:1391999
I need to create a shortcode for display CPT posts. I want to add an atts that print the number of posts_per_page I need in the args for Wp_query.
But If I use
[short_events number=5]
it prints only one post. Where I'm Wrong?
function dis_short_events($atts, $content = null){
ob_start();
$numero = extract(shortcode_atts(array(
'number' => '-1',
), $atts));
$args =array(
'post_type'=>'eventi',
'posts_per_page' => $numero
);
}
add_shortcode('short_events', 'dis_short_events');
I need to create a shortcode for display CPT posts. I want to add an atts that print the number of posts_per_page I need in the args for Wp_query.
But If I use
[short_events number=5]
it prints only one post. Where I'm Wrong?
function dis_short_events($atts, $content = null){
ob_start();
$numero = extract(shortcode_atts(array(
'number' => '-1',
), $atts));
$args =array(
'post_type'=>'eventi',
'posts_per_page' => $numero
);
}
add_shortcode('short_events', 'dis_short_events');
Share
Improve this question
edited Mar 24, 2020 at 10:29
WordPress Speed
2,2833 gold badges19 silver badges34 bronze badges
asked Mar 23, 2020 at 23:11
Micki BenciMicki Benci
212 bronze badges
1
|
1 Answer
Reset to default 0It's typically best practice to not extract your shortcode atts.
function dis_short_events($atts, $content = null){
ob_start();
$numero = shortcode_atts(array(
'number' => '-1',
), $atts);
$args =array(
'post_type'=>'eventi',
'posts_per_page' => $numero['number']
);
本文标签: Shortcode atts for WP Query args
版权声明:本文标题:Shortcode atts for WP Query args 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744644039a2617290.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$atts
), so you could use$atts['number']
to get the "number" parameter. But you extracted the parameters (seeextract()
), so you could also use$number
. So you don't use$numero
, but$number
. – Sally CJ Commented Mar 24, 2020 at 0:53