Support

Account

Home Forums Backend Issues (wp-admin) Sort CPT entries by an ACF field Reply To: Sort CPT entries by an ACF field

  • Yeap, you’re right. This does the trick. Thanks!

    Just for future reference, here is my working code:

    add_action( 'pre_get_posts', 'book_custom_orderby' );
    function book_custom_orderby( $query ) {
      if ( ! is_admin() )
        return;
      if (empty($_GET['orderby'])) {
        $query->set( 'meta_key', 'order-no' );
        $query->set( 'orderby', 'meta_value_num' );
    	$query->set( 'order', 'ASC' );
      }
    }