Site icon Hip-Hop Website Design and Development

Undefined $post in wp_query

I have a custom post type called resources. On it’s post template, I have a widget which will display posts which have the same tags, i.e. If I’m on an article post, the widget will show other articles. To do this, I have the following query:

<?php

$args = array(
    'post_type' => 'resources',
    'category__in'   => wp_get_post_categories($post->ID ),
    'posts_per_page' => 3,
    'post__not_in'   => array($post->ID )
);
$relatedPosts = new WP_Query( $args );

     if( $relatedPosts->have_posts() ) { 

        while( $relatedPosts->have_posts() ) {
            $relatedPosts->the_post(); ?>

            <div class="content">test</div>

        <?php }

        wp_reset_postdata();
    }

?>

But receiving Undefined variable: post errors. How do I avoid getting this error?