How to change the value of a variable using input field?

Please try below snippet of code. HTML : <input name=”getUser” id=”getUser” value=””/> <div id=”user_data”></div> JS (js/my-ajax-script.js) jQuery(document).ready(function($){ $(‘#getUser’).keyup(function(e) { var user_id = e.target.value; console.log(user_id); $.ajax({ url:my_ajax_object.ajaxurl, #add here your ajax url type:’POST’, data:’action=get_this_user_data&user_id=’+user_id , success:function(results) { jQuery(‘#user_data’).html(results); } }); }); }); Ajax (add in functions.php) function my_enqueue() { wp_enqueue_script( ‘ajax-script’, get_template_directory_uri() . ‘/js/my-ajax-script.js’, array(‘jquery’) ); … Read more

Theme customisation – how to store javascript externally when it utilises php variables?

Since it’s a plugin, you should enqueue jQuery first. Inside your add_action(‘wp_head’, function () { before wp_register_script( ‘custom_script’, get_stylesheet_directory_uri() . ‘/custom.js’ ); add : if ( ! wp_script_is( ‘jquery’, ‘enqueued’ )) { //Enqueue jQuery wp_enqueue_script( ‘jquery’ ); } This will check if jQuery is loaded and if not it will load it. Then, in your … Read more

How do I fix Undefined variable using $_POST in function?

Your check is incorrect: right now, it tries to access $_POST[‘rating’], which might not be set, and then checks whether that value is empty. Furthermore, you should scope your if statement with brackets, because right now, your code will try and update the average rating even if no new rating is provided. Try: function save_comment_meta_rating( … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)