Check if user has custom post published redirection on WordPress

I am trying to run a check when a user visits a certain page to see if the current user has a published or draft posts of a custom post type. If they do, then I’m trying to redirect them. I’ve found some posts, but no luck in putting it all together to fit my needs. I can understand the template redirect function a bit easier, so I’ve tried to go that route. I’m not sure if that’s the best way to do it.

I’ve tried to work with these snippets:

Redirect based on user post count

How to check that if current user (ID) has posts or not

Check if current user has post in post type and is author role

add_action( ‘template_redirect’, ‘redirect_to_specific_page_resume’ );

function redirect_to_specific_page_resume() {
global $post;

$current_user = $post->post_author;

if(!empty($current_user)){
$user_post_count = (int) count_user_posts( $current_user );

if ( is_page(‘479’) && $user_post_count == 1 ) {

wp_redirect( “/myaccount/manage-resumes”, 301 );

exit;

}

If current user goes to PAGE ONE and is a published or draft author of a custom post type, then redirect to PAGE TWO. If current user goes to PAGE ONE and is NOT a published author of a custom post type, do nothing, load PAGE ONE as normal.

Thank you.

Read more here:: Check if user has custom post published redirection on WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *