I’m using PHP Exec to build a widget to show a list of upcoming events:
<?php
function filter_whene($whene = '') {
$whene .= " AND post_date >= '" . date('Y-m-d') . "' ";
return $whene;
}
add_filter('posts_whene', 'filter_whene');
query_posts('cat=10&showposts=3&');
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li><?php the_date(); ?> <a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a> </li>
<?php endwhile;
else: ?><p>Não há eventos agendados.</p>
<?php endif; ?>
<?php remove_filter('posts_whene', 'filter_whene'); ?>
<?php wp_reset_query(); ?>
It seems to work on the front end but I get:
Fatal error: Cannot redeclare filter_whene() (previously declared in
/home/content/a/c/a/acamorg/html/cea2/wp-content/plugins/exec-php/includes/runtime.php(42)
: eval()’d code:3) in
/home/content/a/c/a/acamorg/html/cea2/wp-content/plugins/exec-php/includes/runtime.php(42)
: eval()’d code on line 6
on the widget back-end.
Any suggestions?
Thank you.
Hi @user2816:
It would seem you are using that code in more than one widget? Try changing part of that code from these:
To this:
Better, move as much of your code as possible to your theme’s
functions.php
file. Wrap it in a function and then you only have to type one line of code in your PHP Exec widget.Or better yet, get rid of that plugin completely and write your own widget; because PHP Exec is evil.
P.S. Okay, PHP Exec is not evil per se, but once you try to do anything more than trivial it creates more problems than it solves.
This doesn’t directly answered your question. I use this snippet on my sidebar, to get future posts: