Filter for Upcoming Event
Condition: Display all upcoming event items
<?php
add_action( 'events_filter', function( $query ) {
// args
$args = array(
'numberposts' => -1, // -1 means Unlimited Post
'post_type' => 'event', // CPT machine name
'meta_query' => array(
array(
'key' => 'start_date', //ACF field
'value' => date('Y-m-d',strtotime("today")), // Time base of comparison
'compare' => '>=', //Show only events today and future
'type' => 'DATE' // Type of field
),
)
);
$query['meta_query'] = $args;
return $query;
} );
?>
Filter per Taxonomy
<?php
// Showing taxonomy post list ( ̄▽ ̄)ゞ
add_action( 'taxo_filter', function( $query ) {
$tags = get_queried_object()->term_id;
// Specific Taxonomy Query
$taxquery = array(
array(
'taxonomy' => 'custom_posttype', //CPT post type
'field' => 'id',
'terms' => array($tags)
// 'operator'=> 'NOT IN' // In case I need to omit something
)
);
$query['tax_query'] = $taxquery;
return $query;
} );
// Fetch the custom post type tags
add_action( 'pre_get_posts', 'wpa_cpt_tags' );
function wpa_cpt_tags( $query ) {
if ( $query->is_tag() && $query->is_main_query() ) {
$query->set( 'post_type', array( 'post','additionalTaxonomy' ) );
}
}
?>