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.

$args = array(
'post_type' => 'page',
'page_id ' => array( 17, 19, 21 )
$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; ?>

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


$text = apply_filters('the_excerpt', get_post_field('post_excerpt', $post_id));


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.