Support

Account

Home Forums Backend Issues (wp-admin) Access field data inside 'wp_insert_post_data' filter?

Solved

Access field data inside 'wp_insert_post_data' filter?

  • I’m creating a database of addresses using the location addon inside a custom post type. The post title is not relevant to this custom post type, so it has been disabled. I would, however, like to be able to show the most recent location in the various areas that WP would normally show a post title without having to re-code portions of the admin (or addons such as the relationship module which defaults to showing post title in results). Thus I’m attempting to push the address from the ACF location addon to the post title on post save/update.

    The code I’ve created so far only works on post update because there are existing values in the DB for ACF fields, but for this reason it’s of course pushing old data to the post title:

    add_filter( 'wp_insert_post_data', 'change_incident_title' );
    
    function change_incident_title( $post_data )
    { 
      if($post_data['post_type'] == 'incident'){
        $location = get_field('address',$post_data['ID']);
        $post_data['post_title'] = $location['address'];
    
        return $post_data;
      }
    }

    What I’m wondering is if there is any known way to access current ACF data for a post inside the wp_insert_post_data filter before everything is saved to the DB?

  • Whoops, must’ve thought of better terms to search for this time as I just stumbled across something that will hopefully at least guide me in the right direction:

    http://support.advancedcustomfields.com/forums/topic/set-custom-post-type-title-by-acf/

  • Hi @denny

    Thanks for searching and for posting the link

    Great work

    Thanks
    E

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

The topic ‘Access field data inside 'wp_insert_post_data' filter?’ is closed to new replies.