Ask your WordPress questions! Pay money and get answers fast! (more info)

Auto generate post title in WPUF Pro plugin

  • REFUNDED

I have this [[LINK href="http://wordpress.stackexchange.com/questions/214927/change-auto-post-title-generation-according-to-different-post-properties"]]function[[/LINK]] below that automatically generates a post title. I want this function to work with WFUP Pro ([[LINK href="http://docs.wedevs.com/docs/wp-user-frontend-pro/developer-docs/"]]See here for WPUF plugin developer docs[[/LINK]])...

add_action( 'save_post', 'wpse_214927_alter_title', 10, 2 );
function wpse_214927_alter_title ( $post_id, $post_object )
{
// Target only specific post type
if ( 'my_specific_post_type' !== $post_object )
return;

// Remove the current action
remove_action( current_filter(), __FUNCTION__ );

$post_date = $post_object->post_date;
$format_date = DateTime::createFromFormat( 'Y-m-d H:i:s', $post_date );
$date_formatted = $format_date->format( 'Y-m-d' ); // Set correct to display here
$post_author = $post_object->post_author;
$author_name = get_the_author_meta( 'display_name', $post_author ); // Adjust as needed

$my_post = [
'ID' => $post_id,
'post_title' => $author_name . ' Job ' . $date_formatted // Change as needed
];
wp_update_post( $my_post );
}

Answers (4)

2016-02-28

Rempty answers:

Please try this

add_action( 'wpuf_add_post_after_insert', 'wpuf_alter_title' );
add_action( 'wpuf_edit_post_after_update', 'wpuf_alter_title' );
function wpuf_alter_title ( $post_id){
$post_object=get_post($post_id);
$post_date = $post_object->post_date;
$format_date = DateTime::createFromFormat( 'Y-m-d H:i:s', $post_date );
$date_formatted = $format_date->format( 'Y-m-d' ); // Set correct to display here
$post_author = $post_object->post_author;

$author_name = get_the_author_meta( 'display_name', $post_author ); // Adjust as needed

$my_post = [
'ID' => $post_id,
'post_title' => $author_name . ' Job ' . $date_formatted // Change as needed
];
wp_update_post( $my_post );
}


pjeaje comments:

Thanks I'll try it out later today and get back ASAP.


pjeaje comments:

Nope, no joy :(


pjeaje comments:

It doesn't work


Rempty comments:

Please can you add this after
$author_name = get_the_author_meta( 'display_name', $post_author ); // Adjust as needed
just for test


echo $author_name . ' Job ' . $date_formatted.' '.$post_id ;
exit;

And when you save a post from your form, will appear a blank page with the values of author date and post_id


pjeaje comments:

[[LINK href="http://snag.gy/8aZNA.jpg"]]http://snag.gy/8aZNA.jpg[[/LINK]]


Rempty comments:

Maybe can you use the web developer toolbar and check the ajax response in the Network TAB


pjeaje comments:

Thanks for your help but I'd rather just get someone here to solve it. Good luck.

2016-02-28

przepys answers:

is work?


pjeaje comments:

Didn't work

2016-02-28

Bob answers:

does above function work without using wpuf for you?

however please try slightly modified code

add_action( 'wpuf_add_post_after_insert', 'wpuf_alter_title' );
add_action( 'wpuf_edit_post_after_update', 'wpuf_alter_title' );

function wpuf_alter_title ( $post_id){
$post_object=get_post($post_id);
$post_date = $post_object->post_date;
$format_date = DateTime::createFromFormat( 'Y-m-d H:i:s', $post_date );
$date_formatted = $format_date->format( 'Y-m-d' ); // Set correct to display here

$post_author = $post_object->post_author;
$author_name = get_the_author_meta( 'display_name', $post_author ); // Adjust as needed

$my_post = array(
'ID' => $post_id,
'post_title' => $author_name . ' Job ' . $date_formatted // Change as needed
);
// unhook this function so it doesn't loop infinitely
remove_action('save_post', 'wpuf_alter_title');

wp_update_post( $my_post );

// re-hook this function
add_action('save_post', 'wpuf_alter_title');

}

2016-02-28

Reigel Gallarde answers:

PM me if you need help.


pjeaje comments:

@Reigel I'm not going to PM you. Last time I did that you tried to charge me over $100. If you want to be part of this website then post your help here like everyone else. Good luck.


Reigel Gallarde comments:

You might have mistaken me for somebody else.. I have tried searching over our past conversation and I have not found anything that I mention about $100... I only have once involved in your code problem and [[LINK href="http://wpquestions.com/question/showLoggedIn/id/10609"]]this was it[[/LINK]], it was a success, we even have some follow up conversation over PM. Then the next problem/task/question you sent a PM on me. You offered 50 AUD, (you described it as "a simple WordPress function using comment meta" ) I did not reply for I was busy on another project.

as for this question, Rempty's answer is nearly correct or maybe correct. There might be some other problems involved. I can't guess...


pjeaje comments:

@Reigel, I sincerely apologise, it was another well known contributor here. You have never done suck a thing and in fact you have given great help to me in the past. Sorry for the mistake.

It seems there may be another under lying problem. I'll investigate a bit more. I'm posting without any content as well so i'll test it a bit more.