Friday, June 24, 2022
HomeWordPress DevelopmentOrder customized publish sorts by customized fields solely in frontpage

Order customized publish sorts by customized fields solely in frontpage


I’ve this code:

operate my_pre_get_posts( $question ) {
    
    // don't modify queries within the admin
    if( is_admin() ) {
        
        return $question;
        
    }
    
    // solely modify queries for 'formacoes' publish sort
    if( is_front_page() && isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'formacoes' )  {
        
            
        $query->set('posts_per_page', 6);
        $query->set('orderby', 'meta_value');   
        $query->set('meta_key', 'data_inicio');
        $query->set('order', 'ASC');
        $query->set('meta_value', date('Ymd'));
        $query->set('meta_compare', '>=');
        
        
    }
    

    // return
    return $question;

}
add_action('pre_get_posts', 'my_pre_get_posts');

I need to apply this order solely within the frontpage and it is kinda of working.
It is kinda of working as a result of I’ve a button to load extra posts and solely the posts which might be exhibiting already within the web page are ordered accurately, the opposite ones assumes the order set within the posts question (I am utilizing elementor).

What am I lacking?

That is the web page: https://www.atarservicos.pt

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments