获取自定义帖子类型的最后发布日期 - Wordpress

时间:2014-05-15 16:06:30

标签: wordpress date custom-post-type

这可能很简单,但我似乎无法在任何地方找到答案。

我有2种自定义帖子类型。我在我的主页上显示它们。

在每个部分,我都希望有#34;上次更新[日期]"每个部分标题附近的文字。

我找到了<?php get_lastpostdate( $timezone ) ?>,但有没有办法指定您要查询的帖子类型?

[UPDATE]

以下是我根据Howdy_McGee的答案使用的最终代码。我想把日期读作&#34; 5月16日&#34;例如。 “谢谢,这就是我开始走下去的路线。我想我希望不再做另一个WP_Query,但它确实有效。这是我使用的最终代码:

<p class="right last-update"><?php 
    $latest = new WP_Query(array('post_type' => 'car', 'post_status' => 'publish', 'posts_per_page' => 1, 'orderby' => 'modified', 'order' => 'ASC'));
    if($latest->have_posts()){
        $modified_date = $latest->posts[0]->post_modified;
    }
    //Get the last post update and display the date as "10th March"
    $lastpost = strtotime($modified_date);
    $lastmonth = date('F', $lastpost);
    $lastday = date('jS', $lastpost);
    echo 'Last Updated '.$lastday.' '.$lastmonth;
    ?>
</p>

2 个答案:

答案 0 :(得分:3)

如果你在The Loop中,可以使用the_post_modified() function。修改日期将随时以任何方式更改帖子/更新。

<强>更新

好的,让我们运行一个小查询,这样做会拉出最新的帖子,修改或新的。由于它只有1个帖子,我们可以检查它是否有帖子,并获得第一个帖子修改日期。

<?php 
    $latest = new WP_Query(
        array(
            'post_type' => 'car',
            'post_status' => 'publish',
            'posts_per_page' => 1,
            'orderby' => 'modified',
            'order' => 'DESC'
        )
    );

    if($latest->have_posts()){
        $modified_date = $latest->posts[0]->post_modified;
    }
?>

有关Date Format Options, View Codex的完整列表。如果您在The Loop外使用它,则可以使用get_the_modified_date() function。希望它有所帮助!

答案 1 :(得分:0)

我正在工作的网站需要类似的东西,并且如果对其他人有帮助的话,请稍加修改您的代码

var stage = new Konva.Stage({
    container: 'container',
    width: width,
    height: height/2
});

var stage2 = new Konva.Stage({
    container: 'block',
    width: width,
    height: height/2
});

这显示所选post_type的最后修改日期

更新:刚意识到有人发布了这个答案,我只看了第一条“更新”,但是,嗯

相关问题