> 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/excluding-posts-or-cpt-by-parent-id-s.md).

# Excluding posts or CPT by parent ID(s)

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

```php
add_filter( 'asp_query_args', 'asp_exclude_by_parent_ids', 10, 2 );
function asp_exclude_by_parent_ids( $args, $id ) {
  /**
   * Enter the post/cpt parent IDs here, that you want to exclude
   */     
  $ids = array(1, 2, 3, 4, 5, 6);
  
  // -- !! Do not change anything below this line !! --
  $args['post_parent_exclude'] = $ids;
  
  return $args;
}
```

..same code, but to apply only for specific search instances:

```php
add_filter( 'asp_query_args', 'asp_exclude_by_parent_ids', 10, 2 );
  
function asp_exclude_by_parent_ids( $args, $id ) {
  /**
   * Enter the post/cpt parent IDs here, that you want to exclude
   */    
  $ids = array(1, 2, 3, 4, 5, 6);
  /**
   * Search instance IDs you want this code to apply on.
   */
  $search_ids = array(1, 2);      
  
  // --------------------------------------------------
  // -- !! Do not change anything below this line !! --
  // --------------------------------------------------
  if ( in_array($id, $search_ids) )
    $args['post_parent_exclude'] = $ids;
  
  return $args;
}
```
