Title: Include in Custom Query
Last modified: September 14, 2020

---

# Include in Custom Query

 *  Resolved [tokyobear](https://wordpress.org/support/users/tokyobear/)
 * (@tokyobear)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/include-in-custom-query/)
 * Is there a way to force the inclusion of the search excluded posts in a custom
   query? Currently once checked, the plugin removes it from custom queries, as 
   well.
 * Thanks

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

 *  Plugin Contributor [pronskiy](https://wordpress.org/support/users/pronskiy/)
 * (@pronskiy)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/include-in-custom-query/#post-13401540)
 * Hi [@tokyobear](https://wordpress.org/support/users/tokyobear/),
 * Could you give an example of such custom query?
 * In general, the plugin should not affect it, because there is a check `$query-
   >is_search` which means it should only affect search queries.
 * It is always possible to do `$query->set('post__not_in', []);`.
    But if you provide
   an example of your query I could come up with a more elegant solution.
 *  Thread Starter [tokyobear](https://wordpress.org/support/users/tokyobear/)
 * (@tokyobear)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/include-in-custom-query/#post-13402567)
 * Thank you for the prompt response. The below is the code that is used on a single.
   php page in the theme (i.e. within another post). $postarea is defined through
   a custom field. The filter works as intended. But if I check “Exclude from Search
   Results” in any one of the posts then it disappears from the results. Thank you
   in advance for the help.
 * // define query parameters based on attributes
    $options = array( ‘post_type’
   => ‘post’, ‘posts_per_page’ => -1, ‘relation’ => ‘AND’, ‘tax_query’ => array(
   array( ‘taxonomy’ => ‘location’, ‘field’ => ‘slug’, ‘terms’ => $postarea, ‘include_children’
   => true, ‘operator’ => ‘IN’, ), ), );
 * $query = new WP_Query( $options );
 * // run the loop based on the query
    if ( $query->have_posts() ):?>

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

The topic ‘Include in Custom Query’ is closed to new replies.

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

 * 2 replies
 * 2 participants
 * Last reply from: [tokyobear](https://wordpress.org/support/users/tokyobear/)
 * Last activity: [5 years, 8 months ago](https://wordpress.org/support/topic/include-in-custom-query/#post-13402567)
 * Status: resolved