Title: Help with PHP snippet
Last modified: August 3, 2026

---

# Help with PHP snippet

 *  Resolved [simon1402](https://wordpress.org/support/users/simon1402/)
 * (@simon1402)
 * [6 days, 21 hours ago](https://wordpress.org/support/topic/help-with-php-snippet/)
 * Hello,
 * I am using a snippet copied from elsewhere to create a variable “todays_date”
   to use with AQL to identify future events. The snippet seems to work okay when
   added to functions.php but, WPCode flags an error and keeps disabling it. I don’t
   know PHP so I would be very grateful if anybody could diagnose the cause and 
   suggest a solution. The code is:
 * function change_query_date_value( $query_args, $block_query, $inherited ) {
   if(
   isset( $query_args[‘meta_query’] ) && ! empty( $query_args[‘meta_query’] ) ) {
 *     ```wp-block-code
           if ( $query_args['meta_query'][0]['value'] == 'todays_date' ) { $query_args['meta_query'][0]['value'] = date('Ymd'); }
   
       }
       return $query_args;
       ```
   
 * }
   add_filter( ‘aql_query_vars’, ‘change_query_date_value’, 10, 3 );
 * Many thanks,
   Simon

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

 *  Plugin Support [markomiljanovic](https://wordpress.org/support/users/markomiljanovic/)
 * (@markomiljanovic)
 * [5 days, 20 hours ago](https://wordpress.org/support/topic/help-with-php-snippet/#post-18983337)
 * Hi [@simon1402](https://wordpress.org/support/users/simon1402/),
 * The code itself is fine, the problem is almost certainly that it now exists in
   two places. If it’s still in your functions.php and you’ve also added it as a
   WPCode snippet, PHP hits the function change_query_date_value twice and throws
   a fatal “Cannot redeclare” error. WPCode catches that and deactivates the snippet
   to keep your site up, which is why it appears to work in functions.php but gets
   flagged in WPCode.
 * Here’s the same code tidied up, with the braces laid out properly and an extra
   check so it doesn’t warn when the value key isn’t set:
 *     ```wp-block-code
       function change_query_date_value( $query_args, $block_query, $inherited ) {      if ( ! empty( $query_args['meta_query'][0]['value'] ) ) {              if ( 'todays_date' === $query_args['meta_query'][0]['value'] ) {                      $query_args['meta_query'][0]['value'] = date( 'Ymd' );              }      }      return $query_args;}add_filter( 'aql_query_vars', 'change_query_date_value', 10, 3 );
       ```
   
 * If it still gets disabled, please enable Error Logging under WPCode > Settings,
   re-activate the snippet, and send me the error it logs — it names the exact cause
   and line. Here’s how: [https://wpcode.com/docs/using-snippet-error-logging/](https://wpcode.com/docs/using-snippet-error-logging/)
 * Thanks,
 *  Thread Starter [simon1402](https://wordpress.org/support/users/simon1402/)
 * (@simon1402)
 * [4 days, 12 hours ago](https://wordpress.org/support/topic/help-with-php-snippet/#post-18984982)
 * Wow, that is really kind of you. Thank you so much!
 * I don’t think I ever had the code in both functions.php and the wpcode plugin
   but I have put your new code into wpcode on my staging site to see if it throws
   any errors.
 * I have enabled error logging so fingers crossed!
 * Thanks again,
   Simon
 *  Thread Starter [simon1402](https://wordpress.org/support/users/simon1402/)
 * (@simon1402)
 * [4 days, 12 hours ago](https://wordpress.org/support/topic/help-with-php-snippet/#post-18984989)
 * Just checked and the error on the old version is as follows:
 * Undefined array key “value”
 * The error occurred on **line 4** of this snippet’s code (highlighted below).
 * With line 4 being:
 *     ```wp-block-code
           if ( $query_args['meta_query'][0]['value'] == 'todays_date' ) { $query_args['meta_query'][0]['value'] = date('Ymd'); }
       ```
   
 *  Plugin Support [markomiljanovic](https://wordpress.org/support/users/markomiljanovic/)
 * (@markomiljanovic)
 * [3 days, 20 hours ago](https://wordpress.org/support/topic/help-with-php-snippet/#post-18985615)
 * Hi [@simon1402](https://wordpress.org/support/users/simon1402/),
 * Thanks for checking that, it confirms the cause.
 * That first meta_query entry doesn’t always contain a “value” key, so PHP throws
   a warning and WPCode disables the snippet to be safe. The updated snippet I sent
   already accounts for this, it checks that the key exists before comparing it,
   so the warning never fires.
 * Could you give that version a try and let me know if it stays active and your
   future events still filter correctly?
 * Thanks,
 *  Thread Starter [simon1402](https://wordpress.org/support/users/simon1402/)
 * (@simon1402)
 * [1 day, 22 hours ago](https://wordpress.org/support/topic/help-with-php-snippet/#post-18987770)
 * That is working brilliantly. Thank you so much!
    -  This reply was modified 1 day, 22 hours ago by [simon1402](https://wordpress.org/support/users/simon1402/).

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

You must be [logged in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fhelp-with-php-snippet%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * ![](https://ps.w.org/insert-headers-and-footers/assets/icon-256x256.png?rev=2758516)
 * [WPCode - Insert Headers and Footers + Custom Code Snippets - WordPress Code Manager](https://wordpress.org/plugins/insert-headers-and-footers/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/insert-headers-and-footers/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/insert-headers-and-footers/)
 * [Active Topics](https://wordpress.org/support/plugin/insert-headers-and-footers/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/insert-headers-and-footers/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/insert-headers-and-footers/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [simon1402](https://wordpress.org/support/users/simon1402/)
 * Last activity: [1 day, 22 hours ago](https://wordpress.org/support/topic/help-with-php-snippet/#post-18987770)
 * Status: resolved