get_the_tags()
returns an array of tags name, ID, and more. You should store only IDs in an array, and use it in your query.
$post_tag = get_the_tags ( $post->ID );
// Define an empty array
$ids = array();
// Check if the post has any tags
if ( $post_tag ) {
foreach ( $post_tag as $tag ) {
$ids[] = $tag->term_id;
}
}
// Now pass the IDs to tag__in
$args = array(
'post_type' => 'property',
'tag__in' => $ids,
);
// Now proceed with the rest of your query
$related_posts = new WP_Query( $args );
Also, use wp_reset_postdata();
instead of wp_reset_query();
when you are using WP_Query();
.
UPDATE
As pointed out by @birgire, WordPress offers the wp_list_plunk()
function to extract a certain field of each object in a row, which has the same functionality as array_column()
function.
So, we can change this:
// Define an empty array
$ids = array();
// Check if the post has any tags
if ( $post_tag ) {
foreach ( $post_tag as $tag ) {
$ids[] = $tag->term_id;
}
}
To this:
// Check if the post has any tags
if ( $post_tag ) {
$ids = wp_list_pluck( $post_tag, 'term_id' );
}