I am trying to concatenate 2 custom meta fields into one, and saving it to a new custom meta field. The data of those fields is created using a frontend submit plugin that uses the default WordPress functions to save posts. (The data of those fields does save correctly)
The problem is that on Publish, the concatenated field s not saving. However, the meta key is created.
What am I doing wrong? The only thing I can think of is that this code if firing before the other two fields are saved. Is there any way for me to check that?
Here is my code:
add_action('publish_post', 'concat_data');
function concat_data(){
if ( !empty( get_post_meta( get_the_ID(), 'offer_one', true ) ) ) {
$offer_two = get_post_meta( get_the_ID(), 'offer_two', true );
$offer_one = get_post_meta( get_the_ID(), 'offer_one', true );
if(!empty($offer_two) && !empty($offer_one)) {
$concat_data = "Kitchen ".$offer_one." Reg: ".$offer_two;
}
else if(empty($offer_two) && !empty($offer_one)) {
$concat_data = "Kitchen ".$offer_one;
}
update_post_meta( get_the_ID(), 'concat_data', $concat_data );
}
}