Wednesday, November 23, 2022
HomeWordPress Developmentphrases - How can I filter get_terms with publish meta

phrases – How can I filter get_terms with publish meta


I’ve a customized publish kind product with customized taxonomy web_cat and I’ve set a customized subject expiration_date to every of the posts of this kind. I am utilizing that subject in a pre_get_posts to cover posts that expired like this:

perform rt_webinar_pre_query_two($question){
   if ( ! is_admin() && $query->is_main_query() && $query->query_vars['post_type'] == 'product' ) {
    $right this moment = date('Ymd'); // Right this moment's date
        $query->set( 'meta_key', 'event_date' );
        $query->set( 'orderby', 'meta_value' );
        $query->set( 'order', 'ASC');
        $query->set( 'meta_query', array(
            array(
                'key'     => 'expiration_date',
                'evaluate' => '>=',
                'worth'   => date('Ymd'),
                'kind'    => 'numeric',
            )
        ) );
   }
}
add_action( 'pre_get_posts', 'rt_webinar_pre_query_two' );

This filters my posts on my archive web page accurately.

I need a checklist of all phrases as hyperlinks to the tax archives.

I created that hyperlink checklist with this perform:

perform list_webinar_categories() {
    $webcats = get_terms( array(
        'taxonomy' => 'web_cat',
        'hide_empty' => true,
        'dad or mum' => 0
    ) );
    if ( !empty($webcats) ) {
        $catlist="<ul>";
        foreach ($webcats as $webcat) {
            $catlist .= '<li><a href="'.esc_url( get_term_link( $webcat ) ).'">'.$webcat->identify.'</a></li>';
        }
        $catlist .= '</ul>';
        return $catlist;
    }
}
add_shortcode ('webinar-categories', 'list_webinar_categories');

The issue is that this perform just isn’t being filtered by my pre_get_posts. So it’ll create an inventory of classes however won’t cover empty classes primarily based on my expiration date. This leads to a direct 404 web page if that time period has all expired posts or a tax web page that has hyperlinks that go to 404 pages. Is there any solution to apply the expiration_date exclusion to get_terms? (one thing alongside the traces of if_empty)

I considered including

    'meta_query' => array(
        array(
           'key'       => 'expiration_date',
           'worth'     => date('Ymd'),
           'evaluate'   => '>='
        )),

However that might solely verify if the phrases have the expiration date.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments