我有一个网站,该网站最多提供5个非付费会员帖子:
function author_post_count($user_id, $post_type = array(\'YOUR_CUSTOM_POST_TYPE_NAME_HERE\')) {
$args = array(
\'post_type\' => $post_type,
\'author\' => $user_id,
\'posts_per_page\' => -1
);
$query = new WP_Query($args);
return $query->found_posts;
}
然后我使用:
if ( author_post_count(get_current_user_id()) >5) {
SHOW RESTRICTION NOTICE CODE HERE FOR USERS WITH MORE THAN 5 POSTS
}
所以你可以把这两者结合起来
save_post
钩如果您不熟悉,请仔细阅读,尤其是关于避免循环的这一部分:
https://developer.wordpress.org/reference/hooks/save_post/#avoiding-infinite-loops然后您可以将查询更改为使用Date Parameters