I have an old plugin, which used to work fine (years ago). Now I have to press publish twice to publich the post.
The problem is in the blocks below. The used variables are declared above the code below. And there is no error there.
Any effort to help will be much welcome. I have tried to use wp_insert_post instead. The error is still there.
function prfx_meta_save( $post_id ) {
if( is_null( get_post_meta( $post_id, $key = 'navn', true) ) ) {
add_post_meta( $post_id, 'Elev_ID', $navn, true);
} else {
update_post_meta( $post_id, 'navn', $navn );
}
if( is_null( get_post_meta( $post_id, $key = 'Elev_ID', true) ) ) {
add_post_meta( $post_id, 'Elev_ID', $Elev_ID, true);
} else {
update_post_meta( $post_id, 'Elev_ID', $Elev_ID );
}
if( is_null( get_post_meta( $post_id, $key = 'XPRSfag_1', true) ) ) {
add_post_meta( $post_id, 'XPRSfag_1', $XPRSfag_1, true);
} else {
update_post_meta( $post_id, 'XPRSfag_1', $XPRSfag_1 );
}
if( is_null( get_post_meta( $post_id, $key = 'XPRSfag_2', true) ) ) {
add_post_meta( $post_id, 'XPRSfag_2', $XPRSfag_2, true);
} else {
update_post_meta( $post_id, 'XPRSfag_2', $XPRSfag_2 );
}
if( is_null( get_post_meta( $post_id, $key = 'Lærer_1', true) ) ) {
add_post_meta( $post_id, 'Lærer_1', $Lærer_1, true);
} else {
update_post_meta( $post_id, 'Lærer_1', $Lærer_1 );
}
if( is_null( get_post_meta( $post_id, $key = 'Lærer_2', true) ) ) {
add_post_meta( $post_id, 'Lærer_2', $Lærer_2, true);
} else {
update_post_meta( $post_id, 'Lærer_2', $Lærer_2 );
}
if( is_null( get_post_meta( $post_id, $key = 'Year', true) ) ) {
add_post_meta( $post_id, 'Year', $Year, true);
} else {
update_post_meta( $post_id, 'Year', $Year );
}
$katid1 = term_exists( $XPRSfag_1, 'category');
if (is_null($katid1)) {
wp_create_category( $XPRSfag_1 );
}
$katid2 = term_exists( $XPRSfag_2, 'category' );
if (is_null($katid2)) {
wp_create_category( $XPRSfag_2 );
$katid1 = term_exists( $XPRSfag_1 );
$katid2 = term_exists( $XPRSfag_2 );
wp_set_post_terms( $post_id, array( $katid1 , $katid2 ), 'category');
} else {
$katid1 = term_exists( $XPRSfag_1 );
$katid2 = term_exists( $XPRSfag_2 );
wp_set_post_terms( $post_id, array( $katid1, $katid2 ), 'category');
}
}
add_action( 'save_post', 'prfx_meta_save', 99);