Ordinamento custom dei posts in Wordpress admin

Mattepuffo's logo
Ordinamento custom dei posts in Wordpress admin

Ordinamento custom dei posts in Wordpress admin

I posts nella sezione admin di Wordpress sono ordinati di default per data.

Cosa che non mi piace, in quanto trovo più comodo l'ordinamento per nome.

Possiamo facilmente customizzare l'ordine aggiungendo questo codice al functions.php:

function ordinamento_posts_custom($query): void {
  $post_types = get_post_types(array('_builtin' => true), 'names');
  $post_type = $query->get('post_type');
  if (in_array($post_type, $post_types)) {
    if ($query->get('orderby') == '') {
      $query->set('orderby', 'title');
    }
    if ($query->get('order') == '') {
      $query->set('order', 'ASC');
    }
  }
}

if (is_admin()) {
  add_action('pre_get_posts', 'ordinamento_posts_custom');
}

Enjoy!


Condividi

1 Commenti

  • Chekhoslovakia for us were shaken by the almost al

    Chekhoslovakia for us were shaken by the almost all mentioned so that somebody

    05/12/2024

Commentami!