Hi @edcraddock,
I’m trying to do the same thing. Basically, what you need to do is add a hook on saving the post, and assemble the title from the components.
add_action('acf/save_post', 'my_save_post');
function my_save_post($post_id){
// make sure this post type is the kind we want
// get the first and last name fields
// (or whatever field(s) you want to convert into the title
// update the post title (if there isn't one already)
// https://developer.wordpress.org/reference/functions/wp_update_post/
}
I’m using this help page to figure this out: https://www.advancedcustomfields.com/resources/using-acf_form-to-create-a-new-post/ (look at the contact form example)
the acf/save-post hook happens AFTER the post is inserted, so you can use wp_update_post to update the title.
(I’ll post my code here once I actually get it working)
Ah, good ol’ undocumented functions. Thanks for the reference, that’s going to help a lot.
Hmm. How do I unmark my solution so I can flag yours?
Well, after posting (isn’t it how this always works?) I figured out the brute force way to do it. It would be great if there were a function for this.
// get the list of fields in order.
$args = array(
'post_type' => 'acf-field',
'post_parent' => $group_id, // field group
'posts_per_page' => 100,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$all_fields = new WP_Query($args);
$fieldnames = array();
if ($all_fields->have_posts()){
foreach($all_fields->posts as $f){
$fieldnames[] = $f->post_excerpt;
}
}
// get the fields
$fields = get_field_objects();
if( $fields )
{
foreach($fieldnames as $fn){
if (isset($fields[$fn])){
$field = $fields[$fn];
if ($field['value'] == '') continue;
/* do stuff */
}
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.