• I’ve been having a problem with a page that uses a template. The page (wmnf-events.php) has no content and the template for that page (page-wmnf-events.php) uses the following do_shortcode multiple times, once for each category-slug:

    <div id="wmnfevents">
    <?php echo do_shortcode('[ESPRESSO_EVENTS category_slug="wmnf-events" limit="20" title="WMNF Events" order_by="start_date,id" pagination="true"]'); ?>
    </div>
    <div id="communityevents">
    <?php echo do_shortcode('[ESPRESSO_EVENTS category_slug="community-events" limit="20" title="Community Events" order_by="start_date,id" pagination="true"]'); ?>
    </div>
    <div id="musicevents">
    <?php echo do_shortcode('[ESPRESSO_EVENTS category_slug="music-events" limit="20" title="Community Events" order_by="start_date,id" pagination="true"]'); ?>
    </div>
    <div id="nonprofitevents">
    <?php echo do_shortcode('[ESPRESSO_EVENTS category_slug="nonprofit-events" limit="20" title="Community Events" order_by="start_date,id" pagination="true"]'); ?>
    </div>

    The reason I do this instead of listing all categories is to separate into different div tags and I use jQuery to show/hide depending on which category is selected from a drop down list. The page has been working fine for months and all of sudden it started repeating the same records (category-slug) in each div, in this case above it is listing the records for the wmnf-events category four times. If I switch out the category-slug to any of the others, it will display that category four times, like the query is not getting reset. If I put the code into a page like below, all works fine, showing the different records for each div:

    <div id=""wmnfevents"">[ESPRESSO_EVENTS category_slug="wmnf-events" limit="20″ title="WMNF Events" order_by="start_date,id" pagination="true"]</div>
    <div id=""communityevents"">[ESPRESSO_EVENTS category_slug="community-events" limit="20″ title="Community Events" order_by="start_date,id" pagination="true"]</div>
    <div id=""musicevents"">[ESPRESSO_EVENTS category_slug="music-events" limit="20″ title="Community Events" order_by="start_date,id" pagination="true"]</div>
    <div id=""nonprofitevents"">[ESPRESSO_EVENTS category_slug="nonprofit-events" limit="20″ title="Community Events" order_by="start_date,id" pagination="true"]</div>

    Does anyone know what can cause this type of behavior? A really strange thing is the same page/template on our dev site works fine. But when I duplicated that page and template into test-events.php and page-test-events.php, then the problem exists in the page. I have checked all plugins and the WP versions on both sites to be exactly the same. I have also stripped all other code from the test template page including header and footer, still the issue exists.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Try adding wp_reset_postdata() after each shortcode.
    https://codex.ww.wp.xz.cn/Function_Reference/wp_reset_postdata

    <div id="wmnfevents">
    <?php echo do_shortcode('[ESPRESSO_EVENTS category_slug="wmnf-events" limit="20" title="WMNF Events" order_by="start_date,id" pagination="true"]'); ?>
    <?php wp_reset_postdata(); ?>
    </div>
    <div id="communityevents">
    <?php echo do_shortcode('[ESPRESSO_EVENTS category_slug="community-events" limit="20" title="Community Events" order_by="start_date,id" pagination="true"]'); ?>
    <?php wp_reset_postdata(); ?>
    </div>
    <div id="musicevents">
    <?php echo do_shortcode('[ESPRESSO_EVENTS category_slug="music-events" limit="20" title="Community Events" order_by="start_date,id" pagination="true"]'); ?>
    <?php wp_reset_postdata(); ?>
    </div>
    <div id="nonprofitevents">
    <?php echo do_shortcode('[ESPRESSO_EVENTS category_slug="nonprofit-events" limit="20" title="Community Events" order_by="start_date,id" pagination="true"]'); ?>
    <?php wp_reset_postdata(); ?>
    </div>
    Thread Starter webtent

    (@webtent)

    Yes, I tried that already with no help. Looking at the plugin that provides this shortcode, I also see they are using that and the wp_reset_query function as well. It is very perplexing since I have one version on the dev site that works. Any attempts to recreate the page/template have the issue.

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

The topic ‘Problem with multiple shortcode in page template’ is closed to new replies.