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

  • Home
  • SEARCH
  • 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 9184471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:03:34+00:00 2026-06-17T19:03:34+00:00

I’m using the WordPress ajax api to send the result of a php function

  • 0

I’m using the WordPress ajax api to send the result of a php function to the client with .post() ajax. The problem is the value returning a 0 aswell as the numeric value. So if the numeric value is “3” I get “30”.

So here I have a php function that I use to grab the user_id and return the corresponding unseen comment count for that user.

 add_action("wp_ajax_return_unseen_comment_count","return_unseen_comment_count");
 function return_unseen_comment_count() {
    $user_id = $_POST['userId'];
    $count = get_unseen_comment_count($user_id);
    echo $count;
 }

If I place the word “test” after $count I’ll get “3test0”.

I then use an interval to check function for new unseen comments.

$(document).ready(function() {
    var userId = fodAjax.user_id;
    var cmntCount = $(".cmnt-cnt").text();
    if (userId > 0) {
      setInterval(function() {
               data = {
                  action: 'return_unseen_comment_count',
                  userId: userId
               };
               $.post(ajaxurl, data, function (response) {  
                  console.log(response);                  
               });
      }, 10000); //10 seconds
    }
});

Now I use get_unseen_comment_count($user_id) in another function to display the count in my template and it returns the correct value “3” so it’s not doing anything extra that should be adding the 0. What am I missing here?

  • 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-17T19:03:36+00:00Added an answer on June 17, 2026 at 7:03 pm

    You must write exit; after echo statement.

    If the AJAX request fails when the request url is
    wp-admin/admin-ajax.php, it will return either -1 or 0 depending on
    the reason it failed. Additionally, if an AJAX request succeeds, it
    will return a 0
    .

    Reference.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I want to count how many characters a certain string has in PHP, but
I am using JSon response to parse title,date content and thumbnail images and place
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.