• Hello, i have custom fields, but in the following function all posts that don’t have custom field ‘podredba’, are not displayed.

    function category_archive_sort_posts($query) {
      if ( !is_admin() && $query->is_main_query() ) {
        if ( is_category( 1192 ) ) {
          $query->set( 'orderby', 'meta_value_num' );
          $query->set( 'meta_key', 'podredba' );
          $query->set( 'order', 'ASC' );
        }
      }
    }
    
    add_action('pre_get_posts','category_archive_sort_posts');

    How can i merge the following two codes in one?

    $query->set( 'orderby', 'meta_value_num' );
    $query->set( 'meta_key', 'podredba' );
    $query->set( 'order', 'ASC' );

    with

    $query->set( 'orderby', 'date' );
    $query->set( 'order', 'ASC' );

    [ No bumping please. ]

The topic ‘How to add multiple 'orderby' in functions.php’ is closed to new replies.