> 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-current-page-children.md).

# Limit results to current page children

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

```php
add_filter('asp_query_args', 'asp_add_current_parent_dependency', 10, 1);
function asp_add_current_parent_dependency($args) {
  if ( !empty($args['_page_id']) ) {
    $args['post_parent'][] = $args['_page_id'];
    $args['post_parent'] = array_unique($args['post_parent']);
  }
  
  return $args;
}
```

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

```php
add_filter('asp_query_args', 'asp_add_current_parent_dependency', 10, 2);
function asp_add_current_parent_dependency( $args, $id ) {
  /**
   * Search instance IDs you want this code to apply on.
   */
  $search_ids = array(1, 2);     
  
  // -- !! Do not change anything below this line !! --
  // --------------------------------------------------
  if ( !empty($args['_page_id']) && in_array($id, $search_ids) ) {
    $args['post_parent'][] = $args['_page_id'];
    $args['post_parent'] = array_unique($args['post_parent']);
  }
  
  return $args;
}
```
