• Resolved Phil

    (@z2a7o9ph2dw)


    Hi,

    I am trying to display featured events alongside featured posts on one page. The events are maintained using the “events manager” plugin. To flag posts or events as featured I want to use tags – not categories.

    My apporach was the following:

    $posts = get_posts( array(
            'post_type'       => array( 'event', 'post'),
            'posts_per_page'  => 9,
    	'orderby'          => 'date',
    	'order'            => 'DESC',
    	'tax_query'      => array(
                array(
                    'taxonomy'  => 'post_tag',
                    'field'     => 'slug',
                    'terms'     => 'featured'
                )
            )
      ) );
    }

    This works for the posts, but not for the events. I assume it is because events manager uses its own taxonomy for it. But I can’t make it work and can’t find docu on the events manager taxonomy for this….
    I tried:

    
    'taxonomy'  => 'even_tag',
    'field'     => 'slug',
    'terms'     => 'featured'
    
    
    'taxonomy'  => 'even-tags',
    'field'     => 'tag_ID',
    'terms'     => '..THE ID..'
    

    and many more variations, but nothing worked.

    Any suggestions?
    Help would be much appreciated! Thx!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    I didn’t dig too deep into the plugin code but it appears the event tag taxonomy is event-tags. I generally prefer to use the slug field for tax_query arguments, though sometimes the term_id is easier. Be sure you use a valid field argument. Case is significant: 'term_id' !== 'term_ID' tag_id is an invalid field argument. Use either term_id or slug for all taxonomies.

    It’s important with either field to supply the correct terms. The correct slug is easily determined from the taxonomy admin screen that lists all defined tags. The correct term_id can be found in the term’s edit link on the same admin screen. The tag_ID URL parameter value is in fact the term_id. tag_ID is used for all taxonomy term IDs in edit links, not just tags. Valid edit link parameters are entirely unrelated to valid tax_query field arguments, do not conflate the two.

    If you still have trouble, it’s conceivable I’m wrong about event-tags. You would likely be better served by asking for help in the plugin’s dedicated support forum. The plugin authors and user community will then see your topic. They are much better qualified to help you than I am.

    Thread Starter Phil

    (@z2a7o9ph2dw)

    Thank you for looking into this!

    Unfortunately I still couldn’t make it work.
    I will follow your suggestion and move the topic to the plugin forum…

    Thread Starter Phil

    (@z2a7o9ph2dw)

    Made it work:

    $posts = get_posts( array(
            'post_type'       => array( 'event', 'post'),
            'posts_per_page'  => 9,
    	'orderby'          => 'date',
    	'order'            => 'DESC',
    	'tax_query'      => array(
    	    'relation'   => 'OR',
                array(
                    'taxonomy'  => 'post_tag',
                    'field'     => 'slug',
                    'terms'     => array('featured', 'featured-de'),
                ),
                array(
                    'taxonomy'  => 'event-tags',
                    'field'     => 'slug',
                    'terms'     => array('featured'),
                ),
            )
    ) );
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘getting posts and events by tag using tax_query – how to make it work?’ is closed to new replies.