Support » Plugins » Hacks » Two instances of shortcode duplicate data where it shouldn't

  • I have written a plugin for my site that holds membership directory data. There are many categories that a member can be listed in, and as such, I have shortcode that will allow me to display results from a category on any page. For instance, the code

    [tmcategory cat="100" link=""]

    Outputs the data you see here:

    All my shortcode needs is the category number and the link is optional.

    Now on some pages, I want to show more than one list of results. My events page, for example, I want to output the Meeting Spaces members, and then a list of the Catering members. The problem is that if I use a second instance of the shortcode above, it will show the first results a second time, followed by the new results. i.e. if I try to do [tmcategory cat="100"] and then [tmcategory cat="200"] my results page will show:

    Category 100 results
    Category 100 results
    Category 200 results

    I build the output results as a string that I return at the end so it seems simple enough – I need to clear the variable storing my output results after displaying them so that the second instance of the shortcode doesn’t just append the new results to the old. But… I’m just not figuring out how to do that. I’m sure it’s really easy and I am just being dense.

    Help is appreciated. 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • Michael


    Forum Moderator

    i am guessing, as you haven’t published your shortcode function:

    you maybe using a string to gather the data before returnig them as the shortcode result; make sure to initialize the string ($string = '';) at the start of your shortcode function.

    I *think* I tried that before (and couldn’t understand why it didn’t work), but it’s been a while since I tried to fix it, so I will try again and let you know. 🙂

    I feel so stupid. That’s all it was. I swear I tried that before, but I guess I did it wrong somehow!! 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Two instances of shortcode duplicate data where it shouldn't’ is closed to new replies.