• Resolved SpikeTheLobster

    (@spikethelobster)


    I’ve built my first theme and decided to add a simple post expiry function (since all the plugins that do this are rubbish or cost money) but I’m having trouble passing a paramater.

    Here’s the code in the functions.php:

    function expirebydays($numberofdays) {
      if $numberofdays > 0 {
        $daylimit = DATE_SUB(NOW(), INTERVAL $numberofdays DAY);
        $dayquery = "UPDATE $wpdb->posts
          SET $wpdb->posts.post_status = 'expired'
          WHERE $wpdb->posts.post_status = 'publish'
          AND $wpdb->posts.post_type = 'post'
          AND $wpdb->posts.post_date < $daylimit"
        $result = $wpdb->get_results($dayquery);
      }
    }

    Simple enough, but when I upload the new functions file, I get an error:

    “Parse error: syntax error, unexpected ‘$numberofdays’ (T_VARIABLE), expecting ‘(‘ in /blahblahblah/functions.php on line xxx”

    I don’t see why I get a syntax error when I’m using a passed parameter. Obviously I’m missing something.

    (P.S. No, I don’t care about turning it into a proper plugin, having options pages or doing it another, supposedly more efficient way – this is a very simple expiry doodah for my own use! ?? )

    Thanks for any help!

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Passing a parameter to a theme function’ is closed to new replies.