I'm at a loss..
I wanna check the current users post count. If the post count is 1, the user should be redirected. I have tested the following code:
add_action( 'template_redirect', 'redirect_to_specific_page' );
function redirect_to_specific_page() {
$current_user = wp_get_current_user();
if (empty($the_user_id)) {
$the_user_id = $current_user->ID;
}
$user_post_count = count_user_posts( $the_user_id );
if ( is_page('butiktest') && $user_post_count == 1 ) {
wp_redirect( 'enhytte', 301 );
exit;
}
}
However, the above code will redirect no matter the amount of posts.
What am I doing wrong?
EDIT: After pointing out my syntax error was a missing "=", it is still not working.
EDIT 2: The code is in theory working, however, once a post is added, the user_post_count
is not updated, and stays at the previous value.
EDIT3: count_user_posts only count published posts, how do I check for 'pending' and 'draft'?