I got there in the end.
In the ACF function I had, I updated the post but BEFORE that I created the publicize message (including hashtags) and inserted that into the right post meta:
// add the tags to the post title as $custom_message
update_post_meta( $post_id, '_wpas_mess', $custom_message );
// Update the post into the database
wp_update_post( $my_post );
And it works now.
Thanks for your help!
Thanks for that – I tried the plugin but it also didn’t work. I have a feeling I’m going to have to wait for Jetpack to update and allow this.
Oh, Sorry, I thought I did! Here it is 🙂
<?php
//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', 20 );
// 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;
$also_casting_in = $_POST['acf']['field_55c9ee7857c82'];
foreach( $also_casting_in as $value ) {
$pTags = $pTags . ", " . $value;
}
$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);
// adds some hashtags to posts to be publicized by jetpack
add_filter( 'wpas_default_suffix', 'add_default_publicize_hashtag_suffix', 10, 4 );
function add_default_publicize_hashtag_suffix() {
$default_tags = ' #castingcall #audition #actor';
return $default_tags;
}
?>
This is my functions.php with the two functions. The first to change the title and info in the post; the second to the add the tags… which doesn’t work for some reason.
I appreciate anything you might suggest here!
`//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’, 20 );
// 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;
$also_casting_in = $_POST[‘acf’][‘field_55c9ee7857c82’];
foreach( $also_casting_in as $value ) {
$pTags = $pTags . “, ” . $value;
}
$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);
// adds some hashtags to posts to be publicized by jetpack
add_filter( ‘wpas_default_suffix’, ‘add_default_publicize_hashtag_suffix’, 10, 4 );
function add_default_publicize_hashtag_suffix() {
$default_tags = ‘ #castingcall #audition #actor’;
return $default_tags;
}’
I don’t want them added in the post per se, just to the Jetpack publicise plugin. Apparently I can do this through a small function but somehow ACF and the code don’t go together.
When using ACF the title is generated automatically; I use add_action(‘acf/save_post’, ‘my_post_updater’, 20); to change that title.
This new title is publicised by Jetpack but WITHOUT hashtags. I need to add hashtags to it.
Just wondering if you’ve come across this issue before and how to do it.
That is awesome, Mooner! If we ever meet in real life, the beers are on me!
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);
I’m having the same problem which started when I updated to the new version of ACF.
However, even with the remove/add lines to stop looping, it’s still happening…
On the backend that’s fine, but I’m thinking about on a front end form here.
True, alysko, but surely it is the job of the plugin makers to produce a proper tutorial with appropriate screenshots and so on which they can put up here to help others. I run sites where we listen to our customers and provide them with what they need, not ask them to do all the work themselves.
Well, I finally managed it though I have to say that the tutorials here were all but useless. Written by people who already know for people who know a lot all ready!
Sorry, James, but I’m still struggling here.
acf_form( array (
'post_id' => 'new_post',
'post_title' => true,
'post_content' => true,
'new_post' => array(
'post_content' => 'something',
'post_status' => 'draft'
),
'submit_value' => __("Post Casting", 'acf'),
'updated_message' => __("Casting Posted for Moderation", 'acf'),
));
How, in this form, can I change it to see the standard WP fields “Content” and “Title” and my ACF field, “contact_email”?
I really can find where to add those fields (and the default forms on in the docs don’t work for me either).
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!
The most recent ACF Chat Friday featured a live demo of how to register CPTs directly in the plugin, one of our most requested features. Check out the summary below for a replay of the demo, and don’t forget to register for the next session! https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 9, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.