Output input value if matches from an array from get_option

I have created an array in the WP options when activating:

$array = array(
‘Home’,
‘Office’,
‘On site’,
‘Interstate’
);

update_option( ‘user_location’, $array );

I am able to loop through the array and match it against user_meta:

$location_array = get_option(‘user_location’);
foreach( $location_array as $key => $location ) {
$now = ( $key == (get_user_meta( get_current_user_id(), ‘user_meta_location’, true )) ? ‘ checked=”checked”‘ : ” );
echo ‘<input type=”radio” name=”user_meta_location” value=”‘ . $key . ‘”‘ . $now . ‘>’;
}

However, I am trying to create the front end section for an admin to update, edit, and delete items from the array.

Here’s what I’ve tried, but I cannot figure it out:

// url: https://localhost:8890/?get_term_ID=1
$location_array = get_option(‘user_location’);
foreach( $location_array as $key => $location ) {
$now = ( $key == $get_term_ID ? $location : ” ); // $get_term_ID from $_GET[‘term_ID’] from url string
}

and later on in the document, I try to call it:

<input name=”l_name” type=”text” id=”l_name” value=”<?= $now; ?>”>

But I constantly am receiving blank value field.

I have also array_unshift and unset the first in the array to stop WP from causing issues in the calling of ID 0.

Any help would be appreciated!

Read more here:: Output input value if matches from an array from get_option

Leave a Reply

Your email address will not be published. Required fields are marked *