1
Well, I have a call jQuery Ajax
in the header.php
of my theme that is entering a file PHP
at the root of my Wordpress
and return me the echo
test. I need this file to query the banco de dados
and return me some ID's
.
How can I do that? What I’ve developed so far regarding the archive PHP
is below but it didn’t work. I guess I’m not using the right way to connect to the database via WordPress
.
<?php
// ... eu imagino que este include serve para
// instaciar uma conexão com o banco de dados
require('./wp-blog-header.php');
if( isset($_POST['letra']) ){
function retorna(){
global $wpdb;
// Recuperando o termo a ser filtrado no banco de dados
$parametro = isset($_POST['letra']) ? $_POST['letra'] : null;
// Recuperando os ID de todos os registros que respondem a pesquisa
$pesquisas = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_type = 'professores'");
// Por enquanto imprimindo estes valores
foreach ( $pesquisas as $pesquisa ){
print_r($pesquisa->ID);
}
}
retorna();
}
?>
Random errors appear to me 404 and 500 but the paths exist and the permissions are correct. When I remove everything from within the function and leave a echo it works.
Answered ... If you are interested in doing a search in Wordpress and still use an Ajax request for this follows this path there that you get there: http://pastebin.com/P65c3khd
– Marcos Vinicius