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

  • Here is the new code with meta_query but same results.
    There is something I don’t understand…

    
    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' => array(
            'key' => 'date_de_sortie',
            'compare' => 'EXISTS',
          )
        )
      );
      $query->set( 'orderby', array(
        'date' => 'ASC',
        'title'   => 'ASC',
      )
    );
    }
    }