WordPress.org

Ready to get started?Download WordPress

Forums

Two instances of shortcode duplicate data where it shouldn't (4 posts)

  1. sommernyte
    Member
    Posted 3 years ago #

    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="http://www.bellingham.org/membership/member-directory/"]

    Outputs the data you see here:

    http://www.bellingham.org/discover/services/

    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. :)

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    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.

  3. sommernyte
    Member
    Posted 3 years ago #

    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. :)

  4. sommernyte
    Member
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.