Support

Account

Forum Replies Created

  • Hi, @locomo i solved it,

    1) in custom form front end:

     <form id="your-profile" class="nice" action="<?php echo get_edit_profile_url() ?>" method="POST" />
    <?php
    global $current_user;
    							$allCheckbox = get_field('newsletter_preferences','user_'.$current_user->ID);
    							$field_data = get_field_object('your_field_key');
    							$field_key = $field_data['key'];
    							$field = get_field_object($field_key, 'user_'.$current_user->ID);
    						?>
    							<input type="hidden" value="<?php echo 'acf['.$field['key'].']' ?>"/>
    						<?php
    							foreach($field['choices'] as $key => $label){
    								if(is_array($allCheckbox) && in_array($key, $allCheckbox)){
    								    $checked = 'checked';
    								} else {
    								    $checked = '';
    								}
    							echo '<p class="field"><input type="checkbox" '.$checked.' name="acf['.$field['key'].'][]" value="'.$key.'">'.$label.'</p>';
    							}
    						 ?> </form>

    2) in funtions.php

    function update_extra_profile_fields($user_id) {
    	global $current_user;
    $newsletterOptions = isset( $_POST['acf']['your_field_key'] ) ? $_POST['acf']['your_field_key'] : null;
    		$f_id = update_field( 'your_field_key', $newsletterOptions , 'user_'.$user_id);
    }
    add_action('personal_options_update', 'update_extra_profile_fields');
    </form>
    

    this must work so that you can update the fields in the user dahsboard from the custom form.

  • You can use like this:

    //Get all items from fieldname
    $fieldname = get_field('fieldname', $current_user);
    $id = get_the_ID();
    
    $field = get_field_objects($current_user);
    
    $field_name = $field["field_name"]["name"];
    
    if( $field ){
      foreach ( $field["fieldname"]['choices'] as $key => $value) {
    							if ( in_array( $key, $newsletter  ) ) {
    								$checked = 'checked';
    							}else{
    								$checked = '';
    							}
    							echo '<p class="field"><input type="checkbox" '.$checked.' name="'.$field_name.'" value="'.$key.'">'.$value.'</p>';
    						}
    					}
Viewing 4 posts - 1 through 4 (of 4 total)