Support » Plugin: Query Wrangler » Exclude certain post id within shortcode

  • Resolved macmike78


    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


    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 ?

    Each shortcode usage needs to exclude an arbitrary post_id is EXACTLY what I’m going for.

    Thanks for getting back so quickly Jonathan!


    Plugin Author Jonathan Daggerhart


    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.

    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.