• Pete

    (@perthmetro)


    I have this little snippet that allows me to do stuff conditionally if the current user has a published post, or not. I’m wondering how this code could fit within your custom visibility rules code?

    <?php
    $user_id = get_current_user_id(); //the logged in user's id
    $post_type = 'post';
    $posts = count_user_posts( $user_id, $post_type ); //count user's posts
    if( $posts == 0 ){ ?>
    you have none
    <?php } elseif( $posts = 1 ) { ?>
    <?php wp_redirect( 'https://2words.com.au/?page_id=14', 301 ); exit; ?>
    <?php } else { ?>
    else
    <?php } ?>
    • This topic was modified 5 years, 4 months ago by Pete.
  • The topic ‘Hide menu item IF user has a published post’ is closed to new replies.