Get current user and content from dropdown
-
The admin has a drop down of all the current users in the system.
On a particular page it loads content related to that user when they are logged and it’s based off their user ID.
What I’m trying to do is when the admin clicks another users in the drop down the content in that area changes according to the new users ID.
I can get the jQuery to get the users ID and then send it via Ajax. However what I get back is just the number with a 0 behind it. I’ve checked and that means something went wrong. But can’t understand what since it’s returning that value…
jQuery('.users_with_email').on('change',function(){ var userID = jQuery(".users_with_email option:selected").val(); console.log(userID); $.ajax({ url: post_ajax.ajax_url, type: 'post', cache: false, data : { action : 'ajax_user_results', userID : userID }, beforeSend: function() { jQuery('.results_wrapper').find( '.results_content' ).remove(); }, success: function( html ) { jQuery('.user_id').html( html ); jQuery('.results_wrapper').load(document.URL + ' .results_content'); } }); });
add_action( 'wp_ajax_nopriv_ajax_user_results', 'ajax_user_results' ); add_action( 'wp_ajax_ajax_user_results', 'ajax_user_results' ); function ajax_user_results() { // $chosen_user = $_POST['userID']; $chosen_user = '2'; // echo $chosen_user; // print_r($chosen_user); // $user_id = $userID; }
<?php $user_id = $chosen_user; ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Get current user and content from dropdown’ is closed to new replies.