Support

Account

Home Forums Backend Issues (wp-admin) How to filter Options Page on Save or Pre Save

Solved

How to filter Options Page on Save or Pre Save

  • Is there a good way to hook into the save of an ACF options page for sorting values before they are saved to WordPress?

    For example, I have a repeater that I’d like to sort alphabetically by one of the fields when someone saves the options page.

    Right now I’m looking at acf/save_post/ and setting a priority below 10 and editing the $_POST data. Is there a better way to do this?

    
    function my_filter_function( $post_id ) {
        // do some stuff with $_POST['acf']['field_xxxxxxx']
        usort( $_POST['acf']['field_xxxxxxx'], 'sort_by_text_field' );
    }
    add_action( 'acf/save_post', 'my_filter_function', 5, 1 );
    
  • No, there isn’t a better way to do this, or at least, this is the best way that I have found to do this.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.