我将几个网站合并为一个网站,并创建了相应的帖子,并将其post\\u日期(publish date)更改为发布的原始时间。然而(即使我列出了不止一篇文章),根据最近的“post\\u modified”(文章的最后更新),我得到的结果是最后一篇文章。
//编辑-问题的更详细解释
我在旧网站上的原始帖子来自,比方说,2001年1月1日(原始日期)。接下来,我将于2013年9月22日(今天)在新网站上创建一篇帖子,并手动将帖子编辑区域中的发布日期设置为原始日期。我可以在$wpdb中看到post_date=2001-01-01
和post_modified=2013-09-22
. last post快捷码返回包含最新post-modified
日期而非最新日期post_date
.
//编辑-结束
我正在插件的幻灯片中运行一个自定义WP\\u查询,使用一个短标记将其放置在那里。问题是,它需要最后一次修改的帖子,而不是最后一次发布的帖子。
我的短标签代码:
//[latestpost]
function latestpost_func( $atts ){
global $post;
$paged = ( get_query_var(\'paged\') ) ? get_query_var(\'paged\') : 1;
$query = new WP_Query( array( \'paged\' => $paged ) );
$latestpost_arg = array(
\'post_type\' => \'post\',
\'posts_per_page\' => 1,
\'orderby\' => \'date\',
\'order\' => \'DESC\',
\'paged\' => $paged,
\'ignore_sticky_posts\' => 1,
\'category__in\' => array( 127, 253 )
);
$latestpost_query = null;
wp_reset_query();
$latestpost_query = new WP_Query($latestpost_arg);
if ( $latestpost_query -> have_posts() ) :
while ($latestpost_query -> have_posts()) :
$latestpost_query -> the_post();
if (has_post_thumbnail()) {
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), \'full\');
$latestpost_image_div = \'<div class="slide-post-image"><img src="\' . $large_image_url[0] . \'" /></div>\';
}
$latestpost_details_div = \'<div class="slide-post-details-div"><h2 class="latest-post-title">\' . get_the_title() . \'</h2><p class="latest-post-excerpt">\' . get_the_excerpt() . \'</p></div>\';
$latestpost_output = $latestpost_image_div . $latestpost_details_div;
endwhile;
else :
$latestpost_output = \'Sorry, no posts matched your criteria.\';
endif;
return $latestpost_output;
}
add_shortcode( \'latestpost\', \'latestpost_func\' );
SO网友:user116822
以下3个参数将从发布日期起按升序显示帖子(即先显示较旧的帖子)
\'post_status\' => \'publish\', \'orderby\' => \'publish_date\', \'order\' => \'ASC\'
当您将顺序更改为描述时,您将从发布日期开始按降序获得帖子(即最新帖子将首先显示)
\'post_status\' => \'publish\', \'orderby\' => \'publish_date\', \'order\' => \'DESC\'
<?php
$postsPerPage = 10;
$page = 1;
?>
<?php
$query = new WP_Query(array(
\'cat\' => 4,
\'post_status\' => \'publish\',
\'orderby\' => \'publish_date\',
\'order\' => \'ASC\',
\'paged\' => $page,
\'posts_per_page\' => $postsPerPage));
?>