Home › Forums › ACF PRO › Update value function causes timeout › Reply To: Update value function causes timeout
This is where I am right now; commenting out the wp_update_post makes the problem disappear…
I’d appreciate it if you could take a look and maybe see something obvious that I’ve missed!
//Auto add and update Title field:
function my_post_updater( $post_id ) {
// unhook this function to prevent infinite looping
remove_action( 'acf/save_post', 'my_post_updater' );
// change status if admin is user
if ( um_user( "role" ) == 'admin' ) {
$pStatus = "publish";
} else {
$pStatus = "draft";
}
// some variables to use
$pLocation = $_POST['acf']['field_554f18ecbf60c'];
$pLocation = strtoupper( $pLocation );
// get some tags of location + tags
// $pTags = $pLocation . ", " . $_POST['acf']['field_559924b3486da'];
$pTags = $pLocation;
$pTags = strtolower( $pTags );
// get the role & location & build the title
$pTitle = $pLocation . ": " . $_POST['acf']['field_559918d8fce21'];
// add the info at the end if it's locale_get_default
$extrainfo = "";
if ( $_POST['acf']['field_554f3827eee0c'] == 1 ) {
$extrainfo = "[L]";
}
if ( $_POST['acf']['field_55bf6059da1d8'] == "P" ) {
if ( $extrainfo == "[L]" ) {
$extrainfo = "[L,P]";
} else {
$extrainfo = "[P]";
}
}
if ( $_POST['acf']['field_55bf6059da1d8'] == "NP" ) {
if ( $extrainfo == "[L]" ) {
$extrainfo = "[L,NP]";
} else {
$extrainfo = "[NP]";
}
}
if ( $extrainfo != "" ) {
$pTitle = $pTitle . " " . $extrainfo;
}
// add the custom fields box onto the main content
$pContent = $_POST['acf']['field_55991581f79f7'] . "<p>[Custom Fields]</p>";
// Create the update
$my_post = array();
$my_post['ID'] = $post_id;
$my_post['post_title'] = $pTitle;
$my_post['post_status'] = $pStatus;
$my_post['post_content'] = $pContent;
$my_post['tags_input'] = $pTags;
// the permalink bit; begin by getting the slug
$post = get_post($post_id);
$slug = $post->post_name;
if ( is_numeric ( $slug ) ) {
// change to something more tangible otherwise leave alone
$my_post['post_name'] = $pTitle;
}
// Update the post into the database
wp_update_post( $my_post );
// send quick email to tell me
$pTitle = "New Post: " . $pTitle;
$pContent = do_shortcode( $pContent );
$headers = array( 'Content-Type: text/html; charset=UTF-8' );
wp_mail( "[email protected]", $pTitle, $pContent, $headers );
// rehook this function to prevent infinite looping
add_action( 'acf/save_post', 'my_post_updater' );
}
add_action('acf/save_post', 'my_post_updater', 20);
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.