I want to create a new part as multiple checkbox in user profile page that user can check their services.

But the issue is i do not know how to display the checked options after saving as checked and how to display checked options in another page by get_user_meta!!!

my codes:

<input type="checkbox" name="service_name[]" value="Architecture" >Architecture<br>
<input type="checkbox" name="service_name[]" value="Builders and Developeres">Builders and Developeres<br>
<input type="checkbox" name="service_name[]" value="Material Supplier">Material Supplier<br>
<input type="checkbox" name="service_name[]" value="Contractor">Contractor<br>
<input type="checkbox" name="service_name[]" value="Interior Decorator">Interior Decorator<br>
<input type="checkbox" name="service_name[]" value="Property Finance">Property Finance<br>

the way i save them in user meta table:

if( isset($_POST['service_name']) ){
    $data = $_POST['service_name'];
    update_user_meta($userid, 'service_name', $data);

i need your help


First get the data

$data = get_user_meta( $user_id, 'service_name', true);

You find an array of all entries in $data. You can do it this way:

<input type="checkbox" name="service_name[]" value="Architecture" <?php echo in_array('Architecture', $data) ? 'checked' : ''); ?>>Architecture<br>

Untested, but should work.

|improve this answer|||||
  • thanks my friend. how can i display the checked items in another page? it is for user's profile and i want display them to other users – Sh.Dehnavi Mar 12 '19 at 13:10
  • On the same way, u just need the user id of the user where the fields stored – endcoreCL Mar 12 '19 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.