Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 backend. Any suggestions? Thank you.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Hi @user2816:

It would seem you are using that code in more than one widget? Try changing part of that code from these:

function filter_whene($whene = '') {
  $whene .= " AND post_date >= '" . date('Y-m-d') . "' ";
  return $whene;
}
add_filter('posts_whene', 'filter_whene');

To this:

if (!function_exists('filter_whene')) {
  function filter_whene($whene = '') {
    $whene .= " AND post_date >= '" . date('Y-m-d') . "' ";
    return $whene;
  }
}
add_filter('posts_whene', 'filter_whene');

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.

share|improve this answer
    
Thank you. It worked! I'm not using the code in more than one widget and yes, I had already looked for Exec PHP alternatives, as I'm always wary that will break something that I won't know how to fix. Your "create your own widget" suggestion is perfect, of course! –  AnaRita Jan 30 '11 at 13:15

This doesn't directly answered your question. I use this snippet on my sidebar, to get future posts:

<ul>
<?php
query_posts('post_status=future&order=asc&orderby=date');
//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
  echo "<li>";
  echo the_date();
  echo "<br />";
  echo the_title();
  echo"</li>";
endwhile; else:
   echo "<li>there's no future post at the moment.</li>";
endif;
?>
</ul>
share|improve this answer
    
I already went through the "post_status=future" solution (and a meta_value Date one). But then non logged in users could not see the related post. Meta_value would not (I know from experience) be very user friendly. I now use "Future is Now" plugin (which invalidates the future posts solution, as all upcoming events will have a published state), and the above piece of code. I don't need to schedule future posts, so this is the right solution for me. –  AnaRita Jan 30 '11 at 13:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.