Urgent – WordPress keeps creating posts
Question
I was trying to create a WordPress function that altered the post_name. My final function is:
function edit_permalink( $post_id ) {
if ( 'ratings' === get_post_type( $post_id ) ) {
remove_action( 'save_post', 'edit_permalink' );
$slug = get_post_field('post_title', $post_id);
$slug = urlencode($slug);
$date = get_field( 'date_of_rating', $post_id );
$location = wp_get_post_terms( $post_id, 'areas' );
wp_update_post(array('ID' => $post_id, 'post_name' => $slug . "_" . $date->name . "_" . $location[0]->slug));
add_action( 'save_post', 'edit_permalink' );
}
}
add_filter( 'save_post', 'edit_permalink', 10, 2 );
HOWEVER – somewhere along the way, I created a function that is just spewing out multiple posts every second. I’m now up 4000 – still going on – and I can’t stop it!! I’ve tried switching themes, wp_die() – what else can I do!?!
0
custom-post-types, functions, save-post
4 years
2020-03-10T08:50:51-05:00
2020-03-10T08:50:51-05:00 0 Answers
86 views
0
Leave an answer