I'm trying to modify a theme that has custom posts with custom taxonomies. At the bottom of the posts it displays a list of other posts (as in "you might also like...") What I'm trying to do is to filter the posts that are displayed in that area so they match the category of the current post. It's a tour company, I want to display tours on the same area.
The custom posts have a term/taxonomy (I still don't get this) called "st_tour_type" how can I get the name or value of the current post so then I can filter the ones display in the bottom of the page using that one as a reference?
At the moment I'm able to filter them manually if input the slug/name for "st_tour_type" but this doesn't make sense
$args = [
'posts_per_page' => 4,
'post_type' => 'st_tours',
'st_tour_type' => 'lerwanda',
];
I hope you get what I need, it's my first time working with taxonomies...
Update (23Nov): Here's more of the original code
$search_tax_advance = st()->get_option( 'attribute_search_form_tour', 'st_tour_type' );
$terms_posts = wp_get_post_terms(get_the_ID(),$search_tax_advance);
$arr_id_term_post = array();
foreach($terms_posts as $term_post){
$arr_id_term_post[] = $term_post->term_id;
}
$args = [
'posts_per_page' => 4,
'post_type' => 'st_tours',
'post_author' => get_post_field('post_author', get_the_ID()),
'post__not_in' => [$post_id],
'orderby' => 'rand',
'tax_query' => array(
'taxonomy' => $search_tax_advance,
'terms' => $arr_id_term_post,
'field' => 'term_id',
'operator' => 'IN'
),
];