I’ve been having troubles with this plugin at the time of accessing the state of the post or page in which it is located after the shortcode is processed.
Placing this shortcode in a post or page in order to access a list of posts makes any further post information to be lost. I’ve found this to be very annoying in the case of the comment-status property of the posts: even though I disabled comments on the post I was using this plugin in, they kept appearing.
After debugging the plugin, I found out that this is due to the way the list of posts is requested from the database. Once the list is obtained, it is iterated over the $post variable, which is global. The previous post information is overriden, and thus lost, for any later processing. The information stored in that variable from then on is the last post from the list that was obtained from the DB.
I managed to fix this behavior up, and I’m telling you my small patch as an example in case it is useful for anyone else.
In the plugin code, reference the global $post variable at the start of the postlist() function. Then, store the $post variable value into another temporary variable, i.e. $post2.
Just close to the end of the function, after the post list is iterated and the $out variable is filled, but before it is returned, assign the $post2 value back to the global $post var. You’ll keep the original $post values for any further processing outside the plugin.
In a nutshell:
function postlist($attr){
global $post; //MOVE THIS LINE UP
$post2 = $post; //NEW LINE
extract(…// REST OF THE FUNCTION, UP TO THE DB ACCESS AND POST ITERATION.
if ( $query->have_posts() ) :
$out = ”
“;
endwhile;
$out .= “
“;
$post = $post2; //NEW LINE
return $out;
else:
$post = $post2;
return “<p>No Post found.</p>”;
endif;
Finally, the “wp_reset_query();” line is never executed, I’m afraid.
I hope this helps. Best Regards,
Erizo
]]>Short code is in a page. When I press the Modification bouton below the page : le last post in the list appear for modification instead of the page to modify. Modification for Arrange by name has been done.
Thanks
A Philippe
Hi,
Love this plugin for its simplicity, but it would be great if it was possible to display the list by name, either ascending or descending. Is it not possible with the current version?
]]>This plugin can be used to fetch a list of all posts from specific category using shortcode.
== How to Use ==
[postlist cat=”cat1,cat2″ tags=”tag1,tag2,tag3″ number=”-1″ requesttype=”1″]
where
cat : category slug not category name
tages : tag slug not tag name
requesttype : 1 (all of the tags should be present)
0 (any of the tag should be present)
number : the number of posts you want show (use -1 to show all posts)