admin管理员组文章数量:1317915
So I'm trying to get a shortcode working where it calls the posts in the featured story category but I'm having issue getting it to output even just the title from the post. There's no error on the page. But there's nothing else showing either but white space between the nav and footer.
function featured_story() {
$args = array(
'posts_per_page' => 5,
'category_name' => 'featured_story'
);
$last_5_posts_query = new WP_Query( $args );
while($last_5_posts_query->have_posts()) :
$last_5_posts_query->the_post();
$title = get_the_title();
$content .= '<div class="featured-stories">';
$content .= '<h3>' .$title. '</h3>';
endwhile;
return $content;
}
add_shortcode( 'featured-story', 'featured_story' );
So I'm trying to get a shortcode working where it calls the posts in the featured story category but I'm having issue getting it to output even just the title from the post. There's no error on the page. But there's nothing else showing either but white space between the nav and footer.
function featured_story() {
$args = array(
'posts_per_page' => 5,
'category_name' => 'featured_story'
);
$last_5_posts_query = new WP_Query( $args );
while($last_5_posts_query->have_posts()) :
$last_5_posts_query->the_post();
$title = get_the_title();
$content .= '<div class="featured-stories">';
$content .= '<h3>' .$title. '</h3>';
endwhile;
return $content;
}
add_shortcode( 'featured-story', 'featured_story' );
Share
Improve this question
asked Nov 10, 2020 at 7:52
ladycladyc
31 bronze badge
1 Answer
Reset to default 0First thing : initialize variable $content=''; before the while loop. other than that your code is right. there is something you are doing wrong to use shortcode. you should check this link https://developer.wordpress/reference/functions/do_shortcode/#user-contributed-notes and make changes.
also if using for custom post type please add post_type argument in $args
本文标签: postsFeatured Story Shortcode not outputting content
版权声明:本文标题:posts - Featured Story Shortcode not outputting content 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742005019a2411780.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论