Check if post meta exists, and use fallback post meta
For some reason, I’m unable to get this to work and I don’t know why so here I am.
WORKS
This just stores an object in the database as _profile_photo_octopus which is what I want.
get_employee_octopus_profile_photo_args()
:
function employee_profile_photo()
{
$args = get_employee_octopus_profile_photo_args();
$meta_box = display_upload_button($args);
echo $meta_box;
}
WORKS
get_employee_profile_photo_args()
:
function employee_profile_photo()
{
$args = get_employee_profile_photo_args();
$meta_box = display_upload_button($args);
echo $meta_box;
}
NOT WORKING:
I want to be able to use get_employee_profile_photo_args() if a profile picture is set, if not, I want to use get_employee_octopus_profile_photo_args().
Here is the full code attempt:
function employee_profile_photo()
{
$args = get_employee_profile_photo_args();
$octopus_args = get_employee_octopus_profile_photo_args();
if (!is_null($args)) {
$meta_box = display_upload_button($args);
echo $meta_box;
} else {
$meta_box = display_upload_button($octopus_args);
echo $meta_box;
}
}
Could someone tell me what I’m doing wrong here? Would appreciate all the help.
Additional code:
function get_employee_profile_photo_args() {
return array(
'data' => array(
'name' => 'employee_profile_photo',
'type' => 'image',
'width' => 140,
'height' => 190,
'nonce' => wp_create_nonce('employee_profile_photo_nonce')
),
'class' => 'fh-meta-box',
'field' => '_profile_photo'
);
}
function get_employee_octopus_profile_photo_args() {
return array(
'data' => array(
'name' => 'employee_profile_photo',
'type' => 'image',
'width' => 140,
'height' => 190,
'nonce' => wp_create_nonce('employee_profile_photo_nonce')
),
'class' => 'fh-meta-box',
'field' => '_profile_photo_octopus'
);
}
Leave an answer