Learn Tutorials Point - LTP > WordPress > How to Autofill a Custom Post Type title from ACF field in WordPress
How to Autofill a Custom Post Type title from ACF field in WordPress
// Auto fill Title and Slug for CPT’s – ‘companies’, ‘contacts’, ‘properties‘
function lh_acf_save_post( $post_id ) { // Don't do this on the ACF post type if ( get_post_type( $post_id ) == 'acf' ) { return; } $new_title = ''; $new_slug = ''; // Get title from 'companies' CPT acf field 'company_name' if ( get_post_type( $post_id ) == 'gold' ) { $new_title = get_field( 'select_date', $post_id ); $new_slug = sanitize_title( $new_title ); } // Prevent iInfinite looping... remove_action( 'acf/save_post', 'lh_acf_save_post' ); // Grab post data $post = array( 'ID' => $post_id, 'post_title' => $new_title, 'post_name' => $new_slug, ); // Update the Post wp_update_post( $post ); // Continue save action add_action( 'acf/save_post', 'lh_save_post' ); // Set the return URL in case of 'new' post $_POST['return'] = add_query_arg( 'updated', 'true', get_permalink( $post_id ) ); } add_action( 'acf/save_post', 'lh_acf_save_post', 10, 1 );
Author: Learn Tutorials Point
We Well organized and easy-to-understand Interactive tutorials With lots of examples of how to use Tutorials WordPress, PHP, Bootstrap, Bootstrap 4, HTML, CSS, AJAX, jQuery, Woocommerce, Post, Database, Javascript, Theme, Responsive, Templates.
Trending Posts
Tags
ACF
Ading custom columns
admin
Bootstrap
Cart Price
categories
Change Price
class
Code
comments
Create
Creating custom post Type
CSS
current
custom
Customizing
Custom Post
Custom Post Type
Custom Taxonomy
database
Date
Fatch
form
function
HTML
Image
Install
javascript
jQuery
Menu
PHP
Post
Post Type
Price
product
responsive
Resular price
Single product
Table
taxonomy
Theme
Title
woocommerce
Wordpress
Wordpress Code