【发布时间】: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