Order of Projects on homepage

I want to sort the projects on homepage in alphabetical order. As we are talking about nearly 100 projects, it’s no option to do this manually. Currently they are sorted by date.

Any idea for a quick fix?

Hello there,

To do that, you’ll have to add this PHP snippet to child theme’s functions.php file.

    function astrid_child_reorder_projects($query) {
      if ( !is_admin() && is_page() ) {

        $current_meta = $query->get('meta_query');
        $cond_meta = array(
          array(
              'key' => '_wp_page_template',
              'value' => 'page-templates/single-project.php',
          ),
        );

        if( $current_meta == $cond_meta ) {
          $query->set('orderby', 'title');
        }

      }
    }
    add_action('pre_get_posts','astrid_child_reorder_projects', 99999);

If you aren’t running a child theme, you could use a plugin that does the same purpose like Code Snippets or Functionality.

Regards,
Kharis