Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

102
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda