Skip to content
Advertisement

Get custom fields values in filter on wp_insert_post_data

Hi all, thanks for reading.


Environment :

WordPress + Advanced Custom Fields plugin


Problem :

I have searched for hours now and I can’t seem to find the correct syntax to do the following:

When posting a new post, get custom field value in order to automatically replace the title of the post by that value. Example: I create a post and set ’10am’ in my ‘time’ custom field. The title of the post is automatically replaced by ’10am’.


Example:

So I’m adding a filter with the following :

JavaScript

It must be very simple but I have tried every function available on both WP and the plugin’s documentations. I would be very thankful if anyone passing by gave me the solution.

Thanks in advance !

Advertisement

Answer

You can actually access the global $_POST variable for your field value , but i guess you can do it in a cleaner way by using the save_post action to update your post’s title, eg:

JavaScript

assuming that your ACF fieldname is “time”.

Edit: Updated the answer as per Mark Chitty’s answer.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement