Title: Excerpt only generated for first 10 posts
Last modified: July 13, 2017

---

# Excerpt only generated for first 10 posts

 *  [niemand_0](https://wordpress.org/support/users/niemand_0/)
 * (@niemand_0)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/excerpt-only-generated-for-first-10-posts/)
 * If I search and a post shows up in the first ten results, it always has an excerpt.
   If it shows up after the first ten results, no excerpt is displayed.
 * Here is my query on the search page:
 *     ```
       global $query;
       $search_results = $query;
   
       $search_results->query_vars['s'] = get_query_var('s');
       $search_results->query_vars['posts_per_page'] = -1;
   
       relevanssi_do_query($search_results);
       ```
   
 * then I’m looping through the posts:
 *     ```
       foreach($search_results->posts as $key => $result) {
       	$post = get_post($result->ID);
       	include('inc--search-preview.php');
       }
       ```
   
 * In `inc--search-preview.php` I’m using `get_the_excerpt()` to get the excerpt.
   I have also tried `relevanssi_the_excerpt()` and the result was the same.
    -  This topic was modified 8 years, 10 months ago by [niemand_0](https://wordpress.org/support/users/niemand_0/).
      Reason: correcting code

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/excerpt-only-generated-for-first-10-posts/#post-9319338)
 * If you print out $search_results after the relevanssi_do_query(), what’s in it?
   All the posts found, I suppose, but what about the excerpts? Are there Relevanssi-
   generated excerpts for all posts, or just the first ten?
 *  Thread Starter [niemand_0](https://wordpress.org/support/users/niemand_0/)
 * (@niemand_0)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/excerpt-only-generated-for-first-10-posts/#post-9319469)
 * Oh, interesting!
 * The Relevanssi-generated excerpts are there for all posts, in the `post_excerpt`
   property.
 * It isn’t there, however, in my `$post` variable:
 *     ```
       foreach($search_results->posts as $key => $result) {
       	$post = get_post($result->ID);
       	include('inc--search-preview.php');
       }
       ```
   
 * Is it because I’m not in the WordPress “loop”? I tried that but I get a “have_posts()
   is not defined” error:
 *     ```
       while($search_results->have_posts()) : $search_results->the_post();
       	include('inc--search-preview.php');
       endwhile;
       ```
   
 * Am I missing something basic here? I haven’t built a query this way before so
   I’m not sure how to loop through it the “WordPress way”, rather than just doing
   a standard php `foreach` loop.
 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/excerpt-only-generated-for-first-10-posts/#post-9321044)
 * You’re using `get_post()` to fetch the post object. It loads the post object 
   from the database, and that doesn’t include the Relevanssi excerpt.
 * If you have Relevanssi returning post objects, you don’t need to do `get_post()`,
   $result is already a full post object. `$post = $result;`

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Excerpt only generated for first 10 posts’ is closed to new replies.

 * ![](https://ps.w.org/relevanssi/assets/icon-256x256.png?rev=3529670)
 * [Relevanssi - A Better Search](https://wordpress.org/plugins/relevanssi/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/relevanssi/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/relevanssi/)
 * [Active Topics](https://wordpress.org/support/plugin/relevanssi/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/relevanssi/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/relevanssi/reviews/)

## Tags

 * [excerpt](https://wordpress.org/support/topic-tag/excerpt/)

 * 3 replies
 * 2 participants
 * Last reply from: [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * Last activity: [8 years, 10 months ago](https://wordpress.org/support/topic/excerpt-only-generated-for-first-10-posts/#post-9321044)
 * Status: not resolved