Check if post meta exists, and use fallback post meta

Question

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;
}

enter image description here


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;
}

enter image description here


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'
    );
}
0
, , Sem 4 years 2019-11-05T23:20:56-05:00 0 Answers 76 views 0

Leave an answer

Browse
Browse