2017-03-02 42 views
0

我已經安裝了高級自定義字段插件並創建了日期選擇器字段並分配給了帖子。共創建8個帖子。 3個過去的日期和5個職位與未來的日期。在wordpress中隱藏過去的日期帖子

現在,必須將這些發佈日期與當前日期進行比較。

並且,如果發佈日期小於當前日期,則隱藏帖子。

顯示帖子,如果發佈日期greaterthan當前日期。

這是datepicker自定義字段。 the_sub_field('event_end_date')

我試圖用下面的代碼

// current date 
$current_date = date("d/m/Y"); 
// start date (Custom field date picker in posts) 
$value = get_sub_field("event_end_date"); 
if ($current_date < $value) { 
echo 'greater than'; 
}else{ 
echo 'Less than'; 
} 
+0

您已經嘗試了什麼? –

+0

@PrafullaKumarSahu,我試過在我的問題中的代碼 – JRK

+0

你的代碼是如何與郵件查詢相關的? –

回答

0

您應該使用date_query隱瞞過去的職位。請參閱下面的代碼。

$today = getdate(); 
$args = array(
    'date_query' => array(
     array(
      'year' => $today['year'], 
      'month' => $today['mon'], 
      'day' => $today['mday'], 
     ), 
    ), 
); 
$query = new WP_Query($args); 
0

試試這個

// current date 
$current_date = date("Y-m-d"); 
// start date (Custom field date picker) 
$value = get_sub_field("event_end_date"); 
$value_temp = date('Y-m-d', strtotime($value)); 

if (strtotime($current_date) < strtotime($value_temp)) { 
    echo 'greater than'; 
}else{ 
    echo 'Less than'; 
}