admin管理员组文章数量:1303389
I'm trying to get the specific multiple pages excerpts at home page but it is showing all pages, it should show only the requested page IDs, need help please, below is the code I'm using.
<?php
$args = array(
'post_type' => 'page',
'page_id ' => array( 17, 19, 21 )
);
?>
<?php
$my_query = new WP_Query( $args );
while ( $my_query->have_posts() ): $my_query->the_post();
$do_not_duplicate = $post->ID;
?>
<h3><?php the_title(); ?></h3>
<div class="text"> <?php echo wp_trim_words( get_the_content(), 15, '...' ); ?> <a href="<?php echo get_page_link(); ?>" class="read-more">Read More</a> </div>
<?php endwhile; ?>
I'm trying to get the specific multiple pages excerpts at home page but it is showing all pages, it should show only the requested page IDs, need help please, below is the code I'm using.
<?php
$args = array(
'post_type' => 'page',
'page_id ' => array( 17, 19, 21 )
);
?>
<?php
$my_query = new WP_Query( $args );
while ( $my_query->have_posts() ): $my_query->the_post();
$do_not_duplicate = $post->ID;
?>
<h3><?php the_title(); ?></h3>
<div class="text"> <?php echo wp_trim_words( get_the_content(), 15, '...' ); ?> <a href="<?php echo get_page_link(); ?>" class="read-more">Read More</a> </div>
<?php endwhile; ?>
Share
Improve this question
edited Feb 16, 2021 at 21:49
shahid
asked Feb 16, 2021 at 21:27
shahidshahid
13 bronze badges
1 Answer
Reset to default 0It looks like your loop is running through all the posts, your array of post id isn't getting passed.
However, you may be able to make the call using this code
Get excerpt using get_the_excerpt outside a loop
tl;dr
$text = apply_filters('the_excerpt', get_post_field('post_excerpt', $post_id));
https://wordpress.stackexchange/a/150005/26744
本文标签: phpHow to get specific multiple pages excerpts at homepage
版权声明:本文标题:php - How to get specific multiple pages excerpts at homepage? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741745508a2395507.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论