Support

Account

Home Forums ACF PRO Sort post by acf date first and after by title Reply To: Sort post by acf date first and after by title

  • Hello @hube2
    Ok, oh yes I understand.
    I tried with “date_clause” and unfortunately it’s still the same…
    Here is the updated code :

    
    add_action( 'pre_get_posts', 'films_query' );
    function films_query( $query ) {
      if ( !is_admin() && $query->is_main_query() && is_post_type_archive( 'films' ) ) {
        $cat_hide = get_field('categorie_des_films_a_masquer', 'options');
        $taxquery = array(
          array(
            'taxonomy' => 'categorie_films',
            'field' => 'term_id',
            'terms'    => $cat_hide,
            'operator' => 'NOT IN',
          )
        );
        $query->set( 'posts_per_page', '-1' );
        $query->set( 'post_status', 'publish' );
        $query->set( 'tax_query', $taxquery );
        $query->set( 'meta_query', array(
          'relation' => 'AND',
          'date_clause' => array(
            'key' => 'date_de_sortie',
            'compare' => 'EXISTS',
            )
          )
        );
        $query->set( 'orderby', array(
          'date_clause' => 'ASC',
          'title'   => 'ASC',
          )
        );
      }
    }