Support

Account

Forum Replies Created

  • ok, so i think i might of found a solution, adding some “” around the searched value makes it behave as an equals, as opposed to a like, that way, if i were to create a new property with another property type name inside it, lets say “Apartmentslongword”, it doesnt get returned.

    hope this helps someone else who might of run into this problem

    if i have this wrong, please can you explain below,

    THANKS!

  • yes, the modal popups handle login and registration, here is the script that handles all that stuff:

    <?php
    function ajax_auth_init(){	
    	wp_register_style( 'ajax-auth-style', get_template_directory_uri() . '/css/ajax-auth-style.css' );
    	wp_enqueue_style('ajax-auth-style');
    	
    	wp_register_script('validate-script', get_template_directory_uri() . '/js/jquery.validate.js', array('jquery') ); 
        wp_enqueue_script('validate-script');
    
        wp_register_script('ajax-auth-script', get_template_directory_uri() . '/js/ajax-auth-script.js', array('jquery') ); 
        wp_enqueue_script('ajax-auth-script');
    
        wp_localize_script( 'ajax-auth-script', 'ajax_auth_object', array( 
            'ajaxurl' => admin_url( 'admin-ajax.php' ),
            'redirecturl' => home_url(),
            'loadingmessage' => __('Sending user info, please wait...')
        ));
    
        // Enable the user with no privileges to run ajax_login() in AJAX
        add_action( 'wp_ajax_nopriv_ajaxlogin', 'ajax_login' );
    	// Enable the user with no privileges to run ajax_register() in AJAX
    	add_action( 'wp_ajax_nopriv_ajaxregister', 'ajax_register' );
    }
    
    // Execute the action only if the user isn't logged in
    if (!is_user_logged_in()) {
        add_action('init', 'ajax_auth_init');
    }
      
    function ajax_login(){
    
        // First check the nonce, if it fails the function will break
        check_ajax_referer( 'ajax-login-nonce', 'security' );
    
        // Nonce is checked, get the POST data and sign user on
      	// Call auth_user_login
    	auth_user_login($_POST['username'], $_POST['password'], 'Login'); 
    	
        die();
    }
    
    function ajax_register(){
    
        // First check the nonce, if it fails the function will break
        check_ajax_referer( 'ajax-register-nonce', 'security' );
    		
        // Nonce is checked, get the POST data and sign user on
        $info = array();
      	$info['user_nicename'] = $info['nickname'] = $info['display_name'] = $info['first_name'] = $info['user_login'] = sanitize_user($_POST['username']) ;
        $info['user_pass'] = sanitize_text_field($_POST['password']);
    	$info['user_email'] = sanitize_email( $_POST['email']);
    	
    	// Register the user
        $user_register = wp_insert_user( $info );
     	if ( is_wp_error($user_register) ){	
    		$error  = $user_register->get_error_codes()	;
    		
    		if(in_array('empty_user_login', $error))
    			echo json_encode(array('loggedin'=>false, 'message'=>__($user_register->get_error_message('empty_user_login'))));
    		elseif(in_array('existing_user_login',$error))
    			echo json_encode(array('loggedin'=>false, 'message'=>__('This username is already registered.')));
    		elseif(in_array('existing_user_email',$error))
            echo json_encode(array('loggedin'=>false, 'message'=>__('This email address is already registered.')));
        } else {
    	  auth_user_login($info['nickname'], $info['user_pass'], 'Registration');       
        }
    
        die();
    }
    
    function auth_user_login($user_login, $password, $login)
    {
    	$info = array();
        $info['user_login'] = $user_login;
        $info['user_password'] = $password;
        $info['remember'] = true;
    	
    	$user_signon = wp_signon( $info, false );
        if ( is_wp_error($user_signon) ){
    		echo json_encode(array('loggedin'=>false, 'message'=>__('Wrong username or password.')));
        } else {
    		wp_set_current_user($user_signon->ID); 
            echo json_encode(array('loggedin'=>true, 'message'=>__($login.' successful, redirecting...')));
        }
    	
    	die();
    }

    ive tried putting code after the Register the user like this:`
    $user_register = wp_insert_user( $info );
    update_user_meta($info_id, ‘number_of_bedrooms’, $_POST[‘fields’][‘field_55e56dfdabccb’]);`

    but this doesnt even save an empty value to “number_of_bedrooms” in the usermeta table.

    as i understand it, wp_insert_user returns the user id as $info once it successfully registers the user, i guess im missing something somewhere?

  • Thanks Jonathan, that works when i hook it into the register form, but if i add it into a modal popup login form (using AJAX) the fields are empty, im guessing it has something to do with the ajax saving things in a different way? or am i way off the point here?

  • Thanks Jonathan, but i dont seem to be able to make this work, this it the markup of one of the fields im trying to save:

    <input type="number" id="acf-field-price_from" class="number" min="1" max="10000000000000000" step="1" name="fields[field_55e57136adc2e]" value="" placeholder="">

    and this is the hook im adding to my themes functions file:

    function save_additional_user_meta( $user_id ) {
    
        if ( isset( $_POST['field_55e57136adc2e'] ) )
            update_user_meta($user_id, 'number_of_bedrooms', $_POST['field_55e57136adc2e']);
    }
    add_action( 'user_register', 'save_additional_user_meta', 10, 1 );

    ive tried using the id (acf-field-price_from), name (fields[field_55e57136adc2e]) and field key (field_55e57136adc2e) for the post id, and nothing is getting saved to the db

    i tested the hook by removing the if isset, like this

    function save_additional_user_meta( $user_id ) {
    	update_user_meta($user_id, 'number_of_bedrooms', 'test');
    }
    add_action( 'user_register', 'save_additional_user_meta', 10, 1 );

    and it saves the “number_of_bedrooms” as test, so i know the hook is working, just the syntax might be wrong on the field save function?

    any help is much apreciated

  • having the same issue, did you ever find a solution?

Viewing 5 posts - 1 through 5 (of 5 total)