# Add exception to this query based on post id

**URL:** <https://www.phphelp.com/t/add-exception-to-this-query-based-on-post-id/34099>\
**Category:** Beginners - Learning PHP\
**Created:** [October 14, 2021, 7:48am UTC](https://www.phphelp.com/t/add-exception-to-this-query-based-on-post-id/34099 "2021-10-14T07:48:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nathan](https://www.phphelp.com/letter_avatar_proxy/v4/letter/n/c5a1d2/32.png) [@nathan](https://www.phphelp.com/u/nathan)\
**Post date:** [October 14, 2021, 7:48am UTC](https://www.phphelp.com/t/add-exception-to-this-query-based-on-post-id/34099/1 "2021-10-14T07:48:03Z")

</div>

Hi there fist time on this forum!  
I would like to manually “exclude” some specific id’s from this query:

```
function get_pattern_products() {
	
	$collections = [98, 123, 128, 145, 146, 147];
	if (!in_array(get_queried_object()->parent, $collections)) {
		return;	
	}

	$term_id = get_queried_object()->term_id;	
  $args = array(
    'post_type' => 'products_new',
    'tax_query' => array(
      array(
        'taxonomy' => 'collection',
        'field' => 'id',
        'terms' => $term_id
        ),
    ),
  );
  $posts = new WP_Query($args);
  $posts = $posts->get_posts();

	$html = '
'; foreach($posts as $post) { $id = $post-\>ID; $html .= ''; $html .= '
'; $html .= '
 ![]()
'; $html .= '
' . get\_the\_title($id) . '
'; $html .= '

Available sizes

 

' . get\_field('available\_sizes', $id) . '

'; $html .= '
'; $html .= ''; } $html .= '
';
	return $html;
}

add_shortcode('get_pattern_products', 'get_pattern_products');
```

---

<div class="post-metadata">

**Author:** ![skawid](https://www.phphelp.com/letter_avatar_proxy/v4/letter/s/bbe5ce/32.png) [@skawid](https://www.phphelp.com/u/skawid)\
**Post date:** [October 14, 2021, 12:23pm UTC](https://www.phphelp.com/t/add-exception-to-this-query-based-on-post-id/34099/2 "2021-10-14T12:23:49Z")

</div>

Add [`post__not_in`](https://developer.wordpress.org/reference/classes/wp_query/#post-page-parameters) to your $args.
