首先,当使用这种方式访问帖子时,您需要设置一个元值
if( is_user_logged_in() ) {
update_post_meta( $post_id, \'post_readed_by\', get_current_user_id() );
}
然后你可以得到最近访问过的帖子
<?php
$args = array(
\'posts_per_page\' => 10,
\'meta_key\' => \'post_readed_by\',
\'meta_value\' => get_current_user_id(),
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
);
$posts_array = get_posts( $args ); ?>
可以这样使用$posts\\u数组变量
foreach ( $posts_array as $post ) : setup_postdata( $post );
the_title();
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
the_content();
endforeach;
wp_reset_postdata();
希望你了解如何操作这些