Title: Exclude certain post id within shortcode
Last modified: May 9, 2017

---

# Exclude certain post id within shortcode

 *  Resolved [macmike78](https://wordpress.org/support/users/macmike78/)
 * (@macmike78)
 * [9 years ago](https://wordpress.org/support/topic/exclude-certain-post-id-within-shortcode/)
 * I’m trying exclude a single post in my query. I know I can do it via filters 
   > post ids but I need to customize my query on a page by page basis using the
   shortcode. Can this be done argument be targeted in the shortcode?
 * Thank you!

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

 *  Plugin Author [Jonathan Daggerhart](https://wordpress.org/support/users/daggerhart/)
 * (@daggerhart)
 * [9 years ago](https://wordpress.org/support/topic/exclude-certain-post-id-within-shortcode/#post-9113524)
 * Sure, that should be possible. Can you describe the issue a little more? Are 
   you trying to exclude the “current page” the shortcode is being displayed on?
   Or does each shortcode usage need to exclude an arbitrary post_id ?
 *  Thread Starter [macmike78](https://wordpress.org/support/users/macmike78/)
 * (@macmike78)
 * [9 years ago](https://wordpress.org/support/topic/exclude-certain-post-id-within-shortcode/#post-9113565)
 * Each shortcode usage needs to exclude an arbitrary post_id is EXACTLY what I’m
   going for.
 * Thanks for getting back so quickly Jonathan!
 * Mike
 *  Plugin Author [Jonathan Daggerhart](https://wordpress.org/support/users/daggerhart/)
 * (@daggerhart)
 * [9 years ago](https://wordpress.org/support/topic/exclude-certain-post-id-within-shortcode/#post-9113721)
 * This isn’t ideal from a UX perspective, but it should work
 * Where “test” is your query’s slug, and “1234” is the post ID to exclude.
 * `[query slug="test" args="post__not_in%5B%5D=1234"]`
 * What’s going on there is a few things:
 * 1. The shortcode attribute “args” allows you to pass in additional WP_Query arguments
   that override any existing values on the query.
    2. But when dealing with arrays(
   like the post__not_in argument requires), the string has to be a urlencoded. 
   Otherwise it will break the shortcode.
 * Here it is not-urlencoded for reference:
    `[query slug="test" args="post__not_in[]
   =1234"]`
 * Notice those brackets next to “post__not_in”? Those will break the shortcode.
 * The url encoding for left bracket `[` is `%5B`, and the url encoding for right
   bracket `]` is `%5D`. Thus our result `[query slug="test" args="post__not_in%
   5B%5D=1234"]`.
 * Hope that makes sense, let me know if you run into issues. This is the first 
   time I’ve attempted this approach w/ urlencoding the brackets.
 *  Thread Starter [macmike78](https://wordpress.org/support/users/macmike78/)
 * (@macmike78)
 * [9 years ago](https://wordpress.org/support/topic/exclude-certain-post-id-within-shortcode/#post-9113782)
 * Worked like a charm! Thanks so much Jonathan!!
 * I love this plugin!!!

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

The topic ‘Exclude certain post id within shortcode’ is closed to new replies.

 * ![](https://ps.w.org/query-wrangler/assets/icon-256x256.jpg?rev=3279076)
 * [Query Wrangler](https://wordpress.org/plugins/query-wrangler/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/query-wrangler/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/query-wrangler/)
 * [Active Topics](https://wordpress.org/support/plugin/query-wrangler/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/query-wrangler/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/query-wrangler/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [macmike78](https://wordpress.org/support/users/macmike78/)
 * Last activity: [9 years ago](https://wordpress.org/support/topic/exclude-certain-post-id-within-shortcode/#post-9113782)
 * Status: resolved