0

I'm trying to manually display the link of a custom taxonomy term that I have created. The taxonomy is 'event-themes' and the term is 'Boat'. Here's my code:

<?php $themeOne = array(
            'tax_query' => array(
                array(
                    'taxonomy' => 'event-themes',
                    'field' => 'slug',
                    'terms' => 'boat-theme'
                )
            )
        );
        ?>
        <li><a href=""><img src="<?php bloginfo('template_directory'); ?>/images/eventSearch/theme-onFoot.png" /><span><?php echo $themeOne; ?></span></a></li>

I'm not very familiar with PHP so I guess I'm probably missing something very obvious here, but my main aim is to simply 'handpick' the taxonomy term I want, and display a link to the page displaying all posts/pages under it.

Thanks

2 Answers 2

1

In your code you are just storing an "array" in the variable $themeOne. The code you should be using to make the query is:

$themeOne = new WP_Query(array(
'tax_query' => array(
    array(
        'taxonomy' => 'event-themes',
        'terms' => 'boat-theme'
    )
)
));

The result should be an array of objects. You can then access these using the following code:

foreach($themeOne as $term){
    print $term->slug;
}
0

You are mixing functions. The tax query array is intented to modify the query that affect the loop. To just manually print the term link you can do:

<li><a href=""><img src="<?php bloginfo('template_directory'); ?>/images/eventSearch/theme-onFoot.png" /><span><?php echo get_bloginfo('url').'/event-themes/boat-theme'; ?></span></a></li>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.