• Resolved legius

    (@legius)


    Hello,
    I am looking for a way to exclude the current post from the query results.

    I know that, via the WP_Query, I must exclude the {{post:ID}}.
    Here I found how to get values from the current post:
    [query slug="my-query" args="p={{post:ID}}"]

    but the contrary doesn’t seem working. I tried for example this:
    [query slug="my-query" args="p!={{post:ID}}"]
    but without success.

    I try to achieve the following query:
    [qw_query slug="my-query" args="p!={{post:ID}}&s=my-keyword&post-type=post"] (= “show all posts containing the my-keyword excepted the current post”)

    Can you please help?

    https://wordpress.org/plugins/query-wrangler/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Jonathan Daggerhart

    (@daggerhart)

    Hi legius,

    If you do not already have a Post IDs filter on your query, you can achieve this by adding one.

    1. Add Filter – Post IDs
    2. Provide the post IDs: {{post:ID}}
    3. Change “How to treat these post IDs” to show “Not these posts”

    Here is a screenshot of the filter.
    http://www.daggerhart.com/wp-content/uploads/qw-exclude-current-post.png

    This will automatically exclude the current post anywhere the query is show, so you won’t have to use the shortcode arguments.

    Note: The reason i qualified this with “If you do not have a Post IDs filter on your query” is because a query can’t have both a “post__in” and “post__not_in” filters.

    If you already have a Post IDs filter that is including specific posts, then this approach won’t work. Let me know and I’ll come up with something else.

    Thanks,
    Jonathan

    Thread Starter legius

    (@legius)

    Hi Jonathan,
    thanks for your answer, it works exactly as I needed.
    I tried to do it via the shortcode argument without thinking that the {{post:ID}} can be used also in the Query settings filter.

    Perfect!
    And thanks for such a quick help!

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

The topic ‘Exclude current post’ is closed to new replies.