Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

100
Views
Ajax custom function return 0 in wordpress

Here is my test.php page where I have trying to use ajax function to get data in WordPress and working on custom pages. There is no error but it returns 0 on console. Please help me out

script function to call page to get the values from database test.php

<!DOCTYPE html>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>

                                <div>
                                    
                                    <table width="100%" style="background-color: #0066ff; color: white;">
                                        <tr width="75%">
                                            <td>
                                                <h2>Notification</h2>
                                            </td>
                                            <td width="15%">
                                                <i class="fa fa-bell" aria-hidden="true" id="demo"></i>
                                            </td>
                                        </tr>
                                    </table>

                                </div>
                           

<script>
load();
function load() 
{   
    var baseurl = '<?php echo site_url();?>';   
    var ajaxurl = baseurl + '/wp-content/themes/twentyeleven/fetch.php';   
    var ajaxurl = '<?php echo admin_url("admin-ajax.php");?>';
    
    jQuery.ajax({
        url:ajaxurl,
        success:function(result) {
            console.log(result);
        }
    });
}

</script>

fetch.php

    <?php
     
    global $wpdb;
    
    $data=$wpdb->get_results("SELECT * FROM `notification` WHERE to_id = 1154");
    foreach ($data as $value) {
        // code...
        $sender_id= $value->from_id;
        $message= $value->meassage;
        $sender_name = $value->from_name;
    
    echo json_encode($message);
    
    }
    
    
     ?>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use add_action() in WordPress to register an ajax response function.

See https://codex.wordpress.org/AJAX_in_Plugins and https://wpmudev.com/blog/using-ajax-with-wordpress/.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!