Retrieve taxonomy terms and use them in a loop

Question

I have the following code which shows a list of other posts within a single post on the front-end. The $postarea is input as a custom text field in the post back-end. This works but I would like to automate it as the $postarea is the just same as the taxonomy term I select for the post, i.e. if the post is about New York I would select ‘New York’ in the taxonomy field and input “new-york” in the custom text field.

I’ve tried setting $postarea to be the same as the taxonomy(s) selected for that post but get error messages about it being an array or object when it is expecting a string. Any help would be appreciated.

// define query parameters based on attributes
$options = array(
    'post_type' => 'post',
    'posts_per_page' => -1,
    'orderby'=> 'title',
    'order' => 'ASC',
    'category_name' => 'things-to-do',
    'relation' => 'AND',
    'tax_query' => array(
                array(
                    'taxonomy' => 'location',
                    'field'    => 'slug',
                    'terms'    => $postarea
                ),
            ),

);

0
Gecko Boy 4 months 0 Answers 10 views 0

Leave an answer