• I have asked before but I have some more info now.

    I have a plugin using shortcode and then a normal page that i use it on.
    On the page this is what I have

    <ul class="accordion">
    <li>
    <h3 id="1">user1</h3>
    <div>
    [fetch-reviews id="1"][/fetch-reviews]
    </div>
    </li>
    <li>
    <h3 id="2">user2</h3>
    <div>
    [fetch-reviews id="2"][/fetch-reviews]
    </div>
    </li>
    </ul>

    now it displays user1 and all the data from the shortcode, however it does not display user 2 and in fact the shortcode has somehow managed to completely remove the entire li so what gets printed is

    <ul class="accordion">
    <li>
    <h3 id="1">user1</h3>
    <div>
    ...the data from shortcode for user1....
    </div>
    </li>
    </ul>

    Now if I only print user2 it works so it’s not an error there, it’s simply that both cannot be displayed at the same time. very strange.

    also if I use just [fetch-reviews id=”1″] and [fetch-reviews id=”2″] (without closing tags) then nothing gets displayed from the page att all, no javascripts or nothing.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter rickardl

    (@rickardl)

    I found the solution

    First off I had to write [fetch-reviews id=”1″]blah[/fetch-reviews] and [fetch-reviews id=”2″]blah[/fetch-reviews]

    I don’t know why but that was step one.

    Secondly In my shortcode function I did:
    require_once(“dbinit.php”);

    I am not entirely sure why but on second run it failed there so using just require(“dbinit.php”); and everything worked just dandy.

    dbinit.php is not part of WordPress, it must be your own code.
    It sounds like you have a bug in your code, possibly a variable that doesn’t get reset after the first shortcode use, but which something in dbinit resets for you.

    Having said that unless you are accessing an external database I’m not sure why you would have a file called dbinit.

    Thread Starter rickardl

    (@rickardl)

    Hi!

    Yes you are correct it our own code, and I should have mentioned that it is an external db.

    we use a singelton which probably explains why it does not reset properly. just thought I would post my “fix” in case anyone else comes across the same thing.

    Hi Rickardl. I see a couple problems too.

    You didn’t mention what version of WordPress you are using, but if it is lower than v3, then you must use an underscore in place of the hypen in the shortcode tag.

    Second, since you are using closing shortcodes, your content can not be empty. A space would have worked just as well as ‘blah’, but really since your content is obviously not required you should just use [fetch-reviews id=1] without the closing tag. If it is not working that way, then you have a bug.

    It would have been nice to see your source. I have a suspicion, that your shortcode is not RETURNing a string, but PRINTing or ECHOing your code directly instead.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘shortcode plugin fails to show twice and removes html from page’ is closed to new replies.