在特定时间后获得帖子将分两步完成。
您需要存储用户的上次登录时间更改查询以获取以下帖子:modified 在上述登录时间之后以下函数将存储用户的上次登录时间。
// Associating a function to login hook
add_action ( \'wp_login\', \'set_last_login\' );
function set_last_login ( $login ) {
$user = get_userdatabylogin ( $login );
// Setting the last login of the user
update_usermeta ( $user->ID, \'last_login\', date ( \'Y-m-d H:i:s\' ) );
}
然后,您需要收集登录用户的上次登录时间,并按如下所示修改查询。
<?php
// Get current user object
$current_user = wp_get_current_user();
// Get the last login time of the user
$last_login_time = get_user_meta ( $current_user->ID, \'last_login\', true );
// WP_Query with post modified time
$the_query = new WP_Query(
array(
\'date_query\' =>
array(
\'column\' => \'post_modified\',
\'after\' => $last_login_time,
)
)
);
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php // Start the Loop ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php // Show the output ?>
<?php endwhile; ?>
<?php endif; ?>
<?php
// Restore original Post Data
wp_reset_postdata();
?>