From what I can see there is no value set for ct_list_url2
, when this code block executes,
$meta = array('ct_download_link', 'ct_list_url', 'ct_list_url2');
foreach($meta as $dt) {
if($dt == 'ct_list_url2') {
$_POST[$dt] = get_blogspot_url($_POST[$dt]);
}
if(isset($_POST[$dt]) && $_POST[$dt] !== '') {
update_post_meta($post->ID, $dt, $_POST[$dt]);
} else {
delete_post_meta($post->ID, $dt);
}
...
…in fact that goes for any of the values held with in your $meta
array. Your posted values are no where to be found so you need to pass them into your function.
Instead try something like,
foreach($_POST as $key => $val) {
$url = get_blogspot_url($val);
if(isset($key) && $val !== '') {
update_post_meta($post->ID, $key, $url);
} else {
delete_post_meta($post->ID, $key);
}
You need to be careful though because if any of your submitted POST variables have a $key
that returns an empty $val
then your else
condition will run and delete any meta values stored for the given $key
. So if there was a value previously stored in that field it will be deleted. Not sure if this is your intended goal?
If you only want to run your ct_list_url2
POST variable through your get_blogspot_url
function, excluding the other $keys
then you can do something like,
foreach($_POST as $key => $val) {
if(isset($key) && $val !== '') {
if($key == 'ct_list_url2') {
$url = get_blogspot_url($val);
update_post_meta($post->ID, $key, $url);
} else {
//uses $val instead of $url to not run through get_blogspot_url() function
update_post_meta($post->ID, $key, $val);
}
} else {
delete_post_meta($post->ID, $key);
}
}
I hope that helps!