We help IT Professionals succeed at work.

display posts from current taxonomy archive and post with current AND second taxonomy term in same archive

Alicia St Rose
on
326 Views
Last Modified: 2017-03-30
I've got a taxonomy called event-category and another called event-tag.

I'm using the taxonomy-event-tag.php to display any events that are tagged with a specific term. In addition to being tagged they are also given an event-category past-events. The current events show up in the loop in the template. I'd like to have an additional section below that displays past events that share the current tax term.

the taxonomies are event-category and event-tag.

I'm about to pull my hair out trying to figure this out. Been on Google for hours. I'm missing a key understanding, I'm sure. If some one can get me started in the right direction, I'd  love it!!

I've got the follow code:

<?php $args = array(
    'posts_per_page' => -1, 
    'post_type' => 'event',  
    'tax_query' => array(
        'relation' => 'AND'
        array(
            'taxonomy' => 'event-tag',  
            'field' => 'slug',
            'terms' => array(
                'MAT' //I need this to be the term of the current taxonomy!
            )
        ),
        array(
            'taxonomy' => 'event-category',   
            'field' => 'slug',
            'terms' => array(
                'past-events'
            )
			    ),
			  )
			); ?>

Open in new window


I need the event-tag term to be the term of the current taxonomy. That's where I'm stuck.
Comment
Watch Question

Terry WoodsWeb Developer, specialising in WordPress
CERTIFIED EXPERT
Most Valuable Expert 2011

Commented:
Is that code in a loop in your template? If so, you might need to provide the surrounding code.
Alicia St RoseOwner & Principle Developer/Designer
CERTIFIED EXPERT

Author

Commented:
I'm attaching the files. There's the taxonomy archive file  and the template part that's being called into the archive.

taxonomy-event-tag.php

eo-loop-events.php
Terry WoodsWeb Developer, specialising in WordPress
CERTIFIED EXPERT
Most Valuable Expert 2011

Commented:
Try getting the term using:
$term_slug = get_query_var( 'term' );

Open in new window

Terry WoodsWeb Developer, specialising in WordPress
CERTIFIED EXPERT
Most Valuable Expert 2011
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Alicia St RoseOwner & Principle Developer/Designer
CERTIFIED EXPERT

Author

Commented:
I'm trying to list the Posts that share current queried taxonomy term and the term "past-events". Is this code going to show the posts? or the Term slug?
Owner & Principle Developer/Designer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Alicia St RoseOwner & Principle Developer/Designer
CERTIFIED EXPERT

Author

Commented:
I worked out the code and got it working. Terry set me on the right track, however!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.