0

I have 2 custom post types on Wordpress website - Location and Event. Location is connected with Event as meta data (for sorting). For example: some event (Event post type) is taking place in London (Location post type).

All events having in their meta data "London" are shown on page of post type Location - London. The problem is that Event post type has several categories and the one category is named Expired. But posts of all categories are displayed including "Expired". I want to hide this category from the list of posts.

The code on Location page:

$count = 0;
$paged = 1;
if ( get_query_var( 'paged' ) ) {
$paged = get_query_var( 'paged' );
}
$args = array(
'post_type' => 'event',
'paged' => $paged, 
'meta_query' => array(
array( 'key' => 'location', 'value' => get_the_ID() ),
),
);
$tmp_query;
global $wp_query;
$the_query = new WP_Query( $args );
$post_ids = array();
if ( $the_query->have_posts() ) :
if ( $template_type == 1) {
while ( $the_query->have_posts() ) :
$the_query->the_post();
echo event();
endwhile;
} 

Event category is named event_category, ID of Expired category - 2136.

1

I think you should be able to do this with a tax_query in your $args. I could not test this, and I also dont know how the query behaves with a meta and tax query in one.

But I would start with testing something like this:

'tax_query' => array(
    array(
        'taxonomy' => 'event_category', // the used taxonomy
        'field'    => 'term_id', // use ID or slug
        'terms'    => array( 2136 ), // term ID to exclude
        'operator' => 'NOT IN', // "NOT IN" to exclude?, default "IN"
    ),
),

Some more infos in the offical codex.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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