是的,这是可能的,而且代码中的更改非常小。。。
get_posts()
使用WP_Query
, 因此,您可以使用此列表中的所有参数:https://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters
下面是更改后的代码:
$args = array(
\'post_type\' => \'your_custom_post_type\',
\'author\' => get_current_user_id(),
\'date_query\' => array(
array(
\'after\' => \'- X days\', // <- change X to number of days
\'inclusive\' => true,
),
),
\'fields\' => \'ids\', // you only want the count of posts, so it will be much nicer to get only IDs and not all contents from DB
);
$wp_posts = get_posts($args);
if (count($wp_posts)) {
echo "Yes, the current user has \'your_custom_post_type\' posts published!";
} else {
echo "No, the current user does not have \'your_custom_post_type\' posts published.";
}