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
Add a comment  | 

1 Answer 1

Reset to default 0

It 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