有人知道我如何使用下面的脚本来检索自定义帖子类型的最新永久链接,并将其翻转以获取最旧的帖子吗?
This is the link for retrieving custom post type latest post
有人知道我如何使用下面的脚本来检索自定义帖子类型的最新永久链接,并将其翻转以获取最旧的帖子吗?
This is the link for retrieving custom post type latest post
只需更改订单参数DESC
到ASC
:
function Get_First_permalink(){
global $post;
$tmp_post = $post;
$args = array(
\'numberposts\' => 1,
\'offset\' => 0,
\'orderby\' => \'post_date\',
\'order\' => \'ASC\',
\'post_type\' => \'POST_TYPE_NAME\',
\'post_status\' => \'publish\' );
$myposts = get_posts( $args );
setup_postdata($myposts[0]);
$permalink = get_permalink($post->ID);
$post = $tmp_post;
return $permalink;
}
因此,一旦您将该函数粘贴到主题函数中。php和您已更改POST_TYPE_NAME
对于您的帖子类型名称,您可以随时调用它:<a href="<?php echo Get_First_permalink(); ?>">First Post</a>