如何更改计数器以返回日期

时间:2015-08-03 19:04:12

标签: php

您能告诉我如何生成以下脚本: 2015000001 2015000002

代替: 1 2 3

它还应该认识到应该使用的那一年。因此,例如,这将在明年改为2016年。

 //Define the key to store in the database
 define( 'CF7_COUNTER', 'cf7-counter' );

 //Create the shortcode which will set the value for the DTX field
 function cf7dtx_counter(){
     $val = get_option( CF7_COUNTER, 0) + 1;  //Increment the current count
     return $val;
  }
  add_shortcode('CF7_counter', 'cf7dtx_counter');

  //Action performed when the mail is actually sent by CF7
  function cf7dtx_increment_mail_counter(){
      $val = get_option( CF7_COUNTER, 0) + 1; //Increment the current count
      update_option(CF7_COUNTER, $val); //Update the settings with the new count
  }
  add_action('wpcf7_mail_sent', 'cf7dtx_increment_mail_counter');

感谢您的帮助!

Amro的

1 个答案:

答案 0 :(得分:0)

尝试如下。只需添加date功能。

  $value = ("Y-m-d");

        //Create the shortcode which will set the value for the DTX field
         function cf7dtx_counter(){
         $val = get_option( CF7_COUNTER, 0) + 1;  //Increment the current count
$tmp = $value.$val;
         return  $tmp:
          }
          add_shortcode('CF7_counter', 'cf7dtx_counter');

          //Action performed when the mail is actually sent by CF7
          function cf7dtx_increment_mail_counter(){
          $val = get_option( CF7_COUNTER, 0) + 1; //Increment the current count
$tmp = $value.$val;
          update_option(CF7_COUNTER,  $tmp); //Update the settings with the new count
           }
           add_action('wpcf7_mail_sent', 'cf7dtx_increment_mail_counter');