> For the complete documentation index, see [llms.txt](https://knowledgebase.ajaxsearchpro.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://knowledgebase.ajaxsearchpro.com/miscellaneous/post-types/limit-results-to-specific-post-ids-only.md).

# Limit results to specific post IDs only

### Solution #1 - Via back-end option

There is also a [back-end option](https://documentation.ajaxsearchpro.com/advanced-options/excluding-and-including-results/include-by-id) that can be used instead of this code.

### Solution #2 - Via custom code

[What is this, and where do I put this custom code?](/safe-coding-guideline.md)

```php
add_filter( 'asp_query_args', 'asp_include_only_post_ids', 10, 2 );
function asp_include_only_post_ids( $args, $id ) {
  /**
   * Enter the post IDs here. The results will be
   * limited to these posts/CPT only.   
   */     
  $ids = '1, 2, 3, 4, 5';
  $search_ids = 'all';    // Commma separated list of search IDs, if needed
  
  // -- !! Do not change anything below this line !! --
  $search_ids = wpd_comma_separated_to_array($search_ids);
  if ( in_array('all', $search_ids) || in_array($id, $search_ids) ) {
    $ids = wpd_comma_separated_to_array($ids);
    if ( is_array($args['post_in']) ) {
      $args['post_in'] = array_unique(
        array_merge($args['post_in'], $ids)
      );
    } else {
      $args['post_in'] = $ids;
    }
  }
  
  return $args;
}
```

* **$ids** - comma separated list of Post, Page or any custom post type IDs to restrict the results to
