Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8293375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:48:31+00:00 2026-06-08T13:48:31+00:00

I am working in WordPress trying to use an ajax request to fetch user

  • 0

I am working in WordPress trying to use an ajax request to fetch user data by passing the user id.

I can see that the user id sends correctly via AJAX POST but I am getting an internal error message and I don’t know why.

At first I thought it was because I was trying to fetch some custom fields that I had added to the user profile but even when I simplified my script I am still getting the error message.

Any help is much appreciated!

Front End

$('.author').click(function() {

    var id   = $(this).attr('id');
    var temp = id.split('-');
    id = temp[1];

    $.ajax({
            type: 'POST',
            url: 'wp-content/themes/twentyeleven/author_info.php',
            data: {id: id},
            dataType: 'html',
            success: function(data) {
                $('#author-bio').html(data);        
            }
        });     

    return false;
});

author_info.php

$user_id = $_POST['id'];
$forename = get_the_author_meta('user_firstname', $user_id);
$output = $user_id;
echo $output;

Error Message

500 (Internal Server Error) jquery.min.js:4

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T13:48:32+00:00Added an answer on June 8, 2026 at 1:48 pm

    Mathieu added a hackable approach to intercepting a request and redirecting it, which is fine. I prefer to build out AJAX responses that return json_encoded arrays.

    $('.author').click(function() {
    
      var id   = $(this).attr('id');
      var temp = id.split('-');
      id = temp[1];
    
      $.ajax({
        url: 'http://absolute.path/wp-admin/admin-ajax.php',
        data: {'action' : 'ajax_request', 'fn': 'getAuthorMeta', 'id': id},
        dataType: 'json',
        success: function(data) {
          //We expect a JSON encoded array here, not an HTML template.       
        }
      });     
      return false;
    });
    

    Now we build out the function to handle our ajax requests.

    First, we need to define our ajax add_action method ->

    add_action('wp_ajax_nopriv_ajax_request', 'ajax_handle_request');
    add_action('wp_ajax_ajax_request', 'ajax_handle_request');
    

    We need to use both add_action lines here. I won’t get into why. You’ll notice the _ajax_request here. This is the ‘action’ that we sent over in our AJAX function data: {'action' : 'ajax_request'}. We use this hook to validate our AJAX request, it can be anything you’d like.

    Next, we’ll need to build out or function ajax_handle_request.

    function ajax_handle_request(){
      switch($_REQUEST['fn']){
        case 'getAuthorMeta':
          $output = ajax_get_author_meta($_REQUEST['id']);
          break;
        default:
          $output = 'That is not a valid FN parameter. Please check your string and try again';
          break;
      }
      $output = json_encode($output);
      if(is_array($output)){
        return $output;
      }else{
        echo $output;
      }
    }
    

    Now let’s build our function to actually get the author meta.

    function ajax_get_author_meta($id){
      $theMeta = get_the_author_meta([meta_option], $id);
      return $theMeta;
    }
    

    Where [meta_option] is a field provided by WP’s native get_the_author_meta function.

    At this point, we’ll now go back to our success:function(data) and (data) is a reference to the json_encoded array we’ve returned. We can now iterate over the object to get our fields and output them into the page as you’d like.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a Wordpress plugin. I need to pass plugin directories (that can
I'm trying to make a page for use with wordpress and it's almost working,
My wordpress theme comes with integrated Fancybox , you can see it in use
I'm trying to use wordpress' media upload popup in a custom plugin I'm working
I am trying to rewrite a url in wordpress so that I can serve
I'm working on a wordpress site, with a blog post that ends like: http://www.blog.com/?p=2
I'm working in wordpress, trying to figure out how to change the css color
I'm trying to setup a loop in Wordpress that will show all posts from
So I have been working with Wordpress 3.x and trying to build a custom
I'm new to writing WordPress plugins. I'm trying to write a little plugin that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.