簡體   English   中英

如何在動作掛鈎函數內獲取帖子的get_the_date()?

[英]How to get_the_date() of post inside an action hook function?

嘗試在動作掛鈎函數中獲取自定義帖子類型的 當前發布日期 如何在其中獲取當前帖子的所有詳細信息。 或者至少是發布日期? 我已經嘗試了很多東西。 抱歉,很簡單,我是Wordpress的初學者。

add_action('init', 'Theme2035_lyric_register');  

function Theme2035_lyric_register() {   
    echo get_the_date(); 

    ---other code below---

}

我看到您正在尋找the_post操作掛鈎:

function my_the_post_action( $post_object ) {
    $post_date = $post_object->post_date;
    // do something with $post_date
}
add_action( 'the_post', 'my_the_post_action' );

如果要獲取$post_object更多屬性,則可能需要看看WP_Post類引用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM