• Resolved philipt18

    (@philipt18)


    How do you exclude the current post from the results of a loop? I tried the following:

    <table>
    <caption>Other Articles</caption>
    [pass field="id"]
    [loop type="post" category="somecat" exclude="{FIELD}"]
    <tr><td>[field title-link]</td></tr>
    [/loop]
    [/pass]
    </table>

    but the current post was still included. Thanks for your help.

    https://wordpress.org/plugins/custom-content-shortcode/

Viewing 6 replies - 1 through 6 (of 6 total)
  • +1.

    I would also appreciate the help!

    Plugin Author Eliot Akira

    (@miyarakira)

    Good point, I’ll include this as a new parameter in the next update. For the time being, have you tried using exclude=”{ID}”?

    Me too!

    Using the pass field, the excluded id still appears. But if you just set the excluded id manually (by inputting the number), then it works. However, that doesn’t allow for templating.

    Also, whether using the pass code or just the regular loop code, this loop view breaks my JetPack Shares & Likes, which simply disappear from the page. Any ideas why that might be and how to fix it?

    Thanks!

    Oops! I was writing at the same time as you, Eliot.

    To use exclude=”{ID}”, do we still need to include the pass code?

    Plugin Author Eliot Akira

    (@miyarakira)

    Yes, it looks a bit strange but you can do:

    [pass]
      [loop type="post" exclude="{ID}"]
        [field title]
      [/loop]
    [/pass]

    ..and it should exclude the current post. I’ll add a simpler way to do this with a parameter for loop.

    As for JetPack Shares & Likes, I’m not sure why the loop would affect it. I’ve made sure that the loop cleans up after itself (reset query) but it’s possible that there is still something which Shares & Likes expects differently. I’ll try to set up a test case to recreate the issue – please let me know if you find out more.

    Thanks Eliot!

    The Shares & Likes seem to disappear when I try to use the pass shortcode within a custom field. The situation above was the only time it ever happened with the loop shortcode, which I was testing on a post. I tried it with just the loop and then with the pass shortcode and the result was the same.

    However, I wonder if I’m using the pass shortcode correctly. Instead of your example, I would have done this:

    [pass field="id"]
    [loop type="post" exclude="{FIELD}"]
    [field title]
    [/loop]
    [/pass]

    Might that be my problem? Or should that work?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Excluding current post’ is closed to new replies.