How to sort a WP_Query by a custom field AND ALSO filter by a different custom field

to sort the posts by a meta field you need to have this field in meta_query and in orderby like this

$query_args = array(
  'post_type' => 'MY_POSTTYPE_NAME',
  'post_per_page' => -1,
  'meta_query' => array( 
      'show_post_query' => array(
          'key' => 'SHOW_POST',
          'value' => '1'
      ),
      'MY_FIELD_NAME__order_by' => array(
          'key' => 'MY_FIELD_NAME',
          'type' => 'NUMERIC',
          'compare' => 'NUMERIC',
      )
  ),
  'orderby' => array( 'MY_FIELD_NAME__order_by' => 'ASC' ),
);
$query = new WP_Query( $query_args );

Note the MY_FIELD_NAME__order_by does not have “value” set so it will not be used for searching but will be (let’s say) named so you can use it as column name when sorting.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)