Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

101
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda