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');