# Limiting results to specific posts by parent ID

While there is no option to limit the results pool to posts with specific parents only, it is possible with a filter, very easily.

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

```php
add_filter( 'asp_query_args', 'asp_include_only_parent_ids', 10, 2 );
function asp_include_only_parent_ids( $args, $id ) {
  /**
   * Enter the post/cpt prent IDs here. The results will be
   * limited to objects with these parent IDs.   
   */     
  $ids = array(1, 2, 3, 4, 5, 6);
  
  // -- !! Do not change anything below this line !! --
  $args['post_parent'] = $ids;
  
  return $args;
}
```

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

```php
add_filter( 'asp_query_args', 'asp_include_only_parent_ids', 10, 2 );
function asp_include_only_parent_ids( $args, $id ) {
  /**
   * Enter the post/cpt prent IDs here. The results will be
   * limited to objects with these parent IDs.   
   */     
  $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'] = $ids;
  
  return $args;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://knowledgebase.ajaxsearchpro.com/miscellaneous/post-types/limiting-results-to-specific-posts-by-parent-id.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
