1. Home
  2. Amministrazione IT, Gestione Server e Sviluppo Codice
  3. Implementare correttamente pre_get_posts
  1. Home
  2. WordPress
  3. Implementare correttamente pre_get_posts

Implementare correttamente pre_get_posts

In questa guida vedremo come implementare correttamente una funzione agganciata a “pre_get_posts” di WordPress. Usare il seguente codice:

// it does pre_get_posts stuff
function do_pre_get_posts_stuff($query) {
    
    // Not necessary if we are viewing the edito page
    if (is_admin()){
        return;
    }
    
    // We only want to affect the main query
    if (!$query->is_main_query()){
        return;
    }

    /*
    * DO WHATEVER YOU WANT 
    */
}

add_action('pre_get_posts', 'do_pre_get_posts_stuff');
Ultimo aggiornamento il Maggio 11, 2020

Questo articolo รจ stato utile?

Articoli correlati