Hi there,
I have a custom post archive displaying post and author meta at roadtripsharing.com/road_trip
In the archive template I added a do_shortcode(); in the loop, specifically related to the "New Message" button which opens a dialogue to send a direct message to users. Clicking the button only triggers the dialogue for the first post display (though the button does show on all posts, which is even more bizarre). I tried this with a gravity forms shortcode as well and it only rendered the form in the first (top-most) post on the page.
To simplify the question and perhaps make it more useful to others: Suppose I only wanted to show the post title and the shortcode. Would/should this be correct to make the shortcode fully work for all posts?
<?php get_header(); ?>
<?php $road_trips = new WP_Query(array(
'post_type' => 'road_trip'
)); ?>
<?php while($road_trips->have_posts()) : $road_trips->the_post(); ?>
<div>
<?php echo get_the_title(); ?>
<?php echo do_shortcode('[shortcode]'); ?>
</div>
<?php endwhile; ?>
<?php get_footer(); ?>
Here is the code for the actual shortcode as far as I can tell from the plugin source code:
[Large code excerpt removed by moderator per forum rules. Please use the pastebin for all large code excerpts. It works better anyway.]
The add_shortcode call, also in plugin file:
add_shortcode(WPS_PREFIX.'-mail-post', 'wps_mail_post');
However I've also tested it with a couple different shortcodes from different plugins. I have heard from another forum that the issue might be with the shortcode handler not being designed to work more than once per page. If there's a limitation with the shortcode handler, how can that be overcome to display multiple shortcodes per page?
UPDATE: Replaced do_shortcode call with
<?php echo wps_mail_post(); ?>
and that's giving a missing argument error and also only working correctly (clicking "New Message" opens the message dialogue) for the top post at roadtripsharing.com/road_trip (the corresponding buttons on other posts only trigger page refresh and navigation to top of page).
Will look into the $args but what's up with the functions only working for the first post / how to fix it? If the same issue is occuring with the function pasted in rather than using do_shortcode does that mean the issue is not with the shortcode handler after all?
Any tips for getting shortcodes to work for each rendered item in an archive, and not just the first one?