I want to get terms based on a custom field. I created some custom fields as terms that you can choose with a dropdown. For example: I want to display related posts to a single posts by choosing the term.
Thank you for your Help.
<?php
$terms = wp_get_post_terms( $post->ID, 'referenzen_kategorie');
$terms_ids = [];
foreach ( $terms as $term ) {
$terms_ids[] = $term->term_id;
}
$args = array(
'post_type' => 'referenzen',
'orderby' => 'asc',
'posts_per_page' => 3,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'referenzen_kategorie',
'field' => 'slug',
'terms' => bauberatung
)
),
);
$query = new WP_Query($args);
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
?>
<?php $query->the_post();?>
<?php } } ?>
The code that I provide works but I want to replace "bauberatung" with a custom field so that it dynamically displays.