Get events by tag
-
Hello WordPress people,
I would like to retrieve posts based on tags – basically I have a normal post with some tag, and I want to create a custom query where I retrieve all events in the future with that same tag.
I know how to do this in general, but for some reason it is not working with events.Here is what I am trying to do:
<?php $cur_id = get_the_ID(); $terms = get_the_terms( $cur_id , 'shtags' ); $post_type = get_post_type(); foreach ($terms as $term) { $myterm[] = $term->name; } $args = array( 'post_type' => 'event', 'posts_per_page' => '1', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'shtags', 'field' => 'slug', 'terms' => $myterm, 'operator' => 'IN' ) ) ); $my_posts = new WP_Query($args); if($my_posts->have_posts()) : ?> // I can't seem to print permalinks or titles here, it just would print the "parent" page id, title, permalink, etc <?php endif; ?> <?php wp_reset_postdata(); y ?>
Do you think this is possible?
Can you point me in the right direction? Thanks a lot! ??
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Get events by tag’ is closed to new replies.