Try to use a "rapid" ajax, I've the follow code in my my-ajax.php file
define('SHORTINIT',true);
require_once ('../../../../wp-load.php');
require_once ('../../../../wp-config.php');
require_once ('../../../../wp-blog-header.php');
if ((!isset($_POST["action"])) || ($_POST["action"]!=="") || (!is_numeric($_POST["action"]))) {
switch($_POST["action"]){
case 'buscaPost':
if ((isset($_POST["miPost"])) || (isset($_POST["slug"]))){
echo "my actions";
die();
}else{
echo "Fail!";
}
break;
}
}
I try to change the values of wp-load.php path but this is the correct path.
My file my-ajax.php is in
/www/wp-conent/themes/myTheme/folderTheme/myAjax/my-ajax.php
Edit:
I'm not sure if this is the correct way but I need WP_Query to use this in my ajax and now I include the follow requires:
require_once ('../../../../wp-load.php');
require_once ('../../../../wp-includes/taxonomy.php');
require_once ('../../../../wp-includes/meta.php');
require_once ('../../../../wp-includes/pluggable.php');
require_once ('../../../../wp-includes/post.php');
require_once ('../../../../wp-includes/query.php');
But I've the error
get_current_user_id() is not defined
This is include in the wp-includes/pluggable.php. Maybe exists other way to add this wordpress object (WP_Query)??
Now I've other problems with AUTH_COOKIE, LOGGED_IN_COOKIE (this constants are not defined) and call_user_func_array (this said: expect parameter 1 to be a valid callback).
My code actually is:
define('SHORTINIT',true);
define('AUTH_COOKIE',true);
define('LOGGED_IN_COOKIE',true);
// I add this define to correct the error who send me Wordpress, he said this constants are not defined
require_once ('../../../../wp-load.php');
require_once ('../../../../wp-includes/taxonomy.php');
require_once ('../../../../wp-includes/meta.php');
require_once ('../../../../wp-includes/post.php');
require_once ('../../../../wp-includes/user.php');
require_once ('../../../../wp-includes/pluggable.php');
require_once ('../../../../wp-includes/capabilities.php');
require_once ('../../../../wp-includes/query.php');
require_once ('ajax-funciones.php'); //some functions to returns values, actually only return "hi everybody".
if ((!isset($_POST["action"])) || ($_POST["action"]!=="") || (!is_numeric($_POST["action"]))) {
switch($_POST["action"]){
case 'buscaPost':
if ((isset($_POST["miPost"])) || (isset($_POST["slug"]))){
sacaPost($_POST["miPost"],$_POST["slug"]);
die();
}else{
echo "No hay variables";
}
break;
}
}
What can be the mistake?
Other problem is: I've been put a function in my ajax-funciones.php like this:
function sacaPost($idPost,$slugPost){
// Buscamos el contenido del post
$query = array("cat"=>$_POST["miPost"]);
$objetoDatos = new WP_Query($query);
if ($objetoDatos->have_posts()){
while($objetoDatos->have_posts()){
$objetoDatos->the_post();
the_content();
}
wp_reset_postdata();
}else{
echo "any";
}
}
And called this in my-ajax.php but always return "any" and I don't know the reason. It's necesary other way to rescue the values?
wp-config.php
andwp-blog-header.php
is not needed if you loadwp-load.php
. If you seewp-blog-header.php
file content, you will see that this file loadswp-load.php
andwp-template-loader.php
. If you don't need the template engine of WordPress load onlywp-load.php
.wp-config.php
is loaded inwp-load.php
also, you don't to load it manually. – cybmeta Dec 23 '14 at 12:34wp-load-php
,wp-config.php
andwp-blog-loader.php
at the same time generate the error. Remember that, as I said before,wp-config.php
is loaded inwp-load.php
and thatwp-blog-header.php
is loading againwp-load.php
. Use onlywp-load.php
or, if you need the template engine, use onlywp-blog-header.php
. – cybmeta Dec 23 '14 at 12:52