2017-06-02 45 views
0

我需要分開比2017-07-01更早的帖子。WordPress的發佈時間競爭

在循環中我使用這兩個代碼來顯示blogposts。

$compare_date = strtotime("2017-07-01"); 
$post_date = get_the_date(); 

,並試圖他們像

if($compare_date >= $post_date){ 
    //old 
}else{ 
    //new 
} 

比較,但abviously它沒有工作,因爲他們中的一個返回1498867200 等一個1 Haziran 2017 我也試圖把strtotime(get_the_date())但結果是空的。

我該如何做到這一點?

回答

1

獲取POST_DATE在相同的格式compare_date

現在,隨着日期

$compare_date = "2017-07-01"; 
$post_date = get_the_date('Y-m-d'); 
if($compare_date >= $post_date){ 
    //old 
}else{ 
    //new 
} 

比較現在比較時間

$compare_date = strtotime("2017-07-01"); 
$post_date = strtotime(get_the_date('Y-m-d')); 
if($compare_date >= $post_date){ 
    //old 
}else{ 
    //new 
} 

沒有測試,但是可行的解決方案。