【问题标题】:Filter Gravity Forms Entries By Date按日期过滤重力表格条目
【发布时间】:2017-07-17 14:32:38
【问题描述】:

我正在尝试在两个特定日期之间过滤(显示)我网站前端的重力表格条目。一个是今天(当前日期)和一个在网站后端添加的自定义日期。

所以只有在自定义日期和当前日期之间提交的条目。

我有两个变量存储这些日期: $new_start_date 是自定义日期,并且 $end_date 是当前日期。

我的代码输出了 200 个条目,但其中一些在自定义开始日期之前。

下面是我的查询代码:

<?php
//Get the Form ID to get the entries from and store it within a varibale
$form_id = GFAPI::get_form(2);


// Get Dates
$date_page_id = get_field( 'update_dates_page_link', 'options', false, false );           
$start_date = get_field( 'oak_submission_date', $date_page_id ); // date of the last submission date
$end_date   = date( 'Y-m-d', time() ); //get today's date   

// Convert start_date to match end_date format
$new_start_date = DateTime::createFromFormat( 'd/m/Y', $start_date );
$new_start_date = $new_start_date->format( 'Y-m-d' );


    $search_criteria = array(
        'status'        => 'active',
        'start_date'    => $new_start_date,
        'end_date'      => $end_date,
        'field_filters' => array(
            array(
                'key'   => '53', // Trust name field
                'value' => 'Oak Trust',
            ),
            array(
                'key'   => '49', // Grant Made field
                'value' => 'No',
            ),
        ),
    );  
    $sorting = null;
    $paging  = array( 'offset' => 0, 'page_size' => 200 );

    $entries = GFAPI::get_entries( $form_id, $search_criteria, $sorting, $paging );

// 输出到屏幕的代码

foreach ( $entries as $entry) :

    echo '<li>';

    echo 'ID: '. $entry[68] .' : ' . $entry[2] .' : Submission Date: '. $entry[54];

    echo '</li>';

endforeach;

【问题讨论】:

    标签: php wordpress gravity-forms-plugin


    【解决方案1】:

    GFAPI::get_form(2) 不返回表单 ID,而是返回表单。试试这个:

    $entries = GFAPI::get_entries( 2, $search_criteria, $sorting, $paging );
    

    【讨论】:

      猜你喜欢
      • 2019-09-21
      • 1970-01-01
      • 2017-12-16
      • 2021-11-25
      • 2014-05-30
      • 2015-01-31
      • 2022-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多