Title: Passing a parameter to a theme function
Last modified: August 21, 2016

---

# Passing a parameter to a theme function

 *  Resolved [SpikeTheLobster](https://wordpress.org/support/users/spikethelobster/)
 * (@spikethelobster)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/passing-a-parameter-to-a-theme-function/)
 * 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)

 *  [nathan_dawson](https://wordpress.org/support/users/nathan_dawson/)
 * (@nathan_dawson)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/passing-a-parameter-to-a-theme-function/#post-3976895)
 * Change
    `if $numberofdays > 0 {`
 * To
    `if ( $numberofdays > 0 ) {`
 *  Thread Starter [SpikeTheLobster](https://wordpress.org/support/users/spikethelobster/)
 * (@spikethelobster)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/passing-a-parameter-to-a-theme-function/#post-3976902)
 * Oh dear. 🙂
 * I had forgotten that syntax errors always look like they’re saying one thing 
   is wrong when they actually mean another. Now I feel very silly.
 * Thanks very much, so obvious!
 *  Thread Starter [SpikeTheLobster](https://wordpress.org/support/users/spikethelobster/)
 * (@spikethelobster)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/passing-a-parameter-to-a-theme-function/#post-3977007)
 * EDIT: Removed. Figured it out.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Passing a parameter to a theme function’ is closed to new replies.

 * 3 replies
 * 2 participants
 * Last reply from: [SpikeTheLobster](https://wordpress.org/support/users/spikethelobster/)
 * Last activity: [12 years, 10 months ago](https://wordpress.org/support/topic/passing-a-parameter-to-a-theme-function/#post-3977007)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
