• Resolved Kimantis_Creative_Group

    (@kimantis_creative_group)


    Hey! Thank you for the great plugin. I had a save_post filter that was updating the published date and now it stopped working.

    add_action('acf/save_post', 'update_post_date_from_acf', 20 );
    function update_post_date_from_acf($post_id) {
    	remove_filter('acf/save_post', 'update_post_date_from_acf', 10);
    	$post_date = get_field('update_post_date');
    	$post = wp_update_post(array(
    		'ID' => $post_id,
    		'post_date' => $post_date));
    }
    

    Using the forms, the data is saved and everything but it’s not replacing the published date. I just want to do this to add previous clients.

    Not sure if there’s a better way,
    Thanks,
    Joey

Viewing 1 replies (of 1 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback! It looks like your request is about a custom development tho. There’s not much information about what you’re trying to achieve there. Are you using the ACFE Forms module?

    There’s also some weird things in your code, for example your use remove_filter() at the priority:10 when that priority has already passed (you’re already in priority:20). That line does nothing.

    You also use get_field() without any context (no $post_id) which is not recommended. But it also depends if you’re using ACFE Forms or not.

    If you’re using the ACFE Forms module, I would recommend you to use the acfe/form/submit/post_args filter to change the publish date. See documentation.

    Usage example:

    add_filter('acfe/form/submit/post_args/form=my-form', 'my_form_post_args', 10, 4);
    function my_form_post_args($args, $type, $form, $action){
        
        // Retrieve value from field input update_post_date
        $post_date = get_field('update_post_date');
        
        $args['post_date'] = $post_date;
        
        return $args;
        
    }
    

    Also you should make sure that your date is correctly formatted there.

    Hope it helps!

    Regards.

Viewing 1 replies (of 1 total)

The topic ‘Change Published Date’ is closed to new replies.