0

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?

  • Loading wp-config.php and wp-blog-header.php is not needed if you load wp-load.php. If you see wp-blog-header.php file content, you will see that this file loads wp-load.php and wp-template-loader.php. If you don't need the template engine of WordPress load only wp-load.php. wp-config.php is loaded in wp-load.php also, you don't to load it manually. – cybmeta Dec 23 '14 at 12:34
  • By the way, this code is not the one I gave you in the other question but you said, more than once, that you had not modified it. Please, for future questions, be honest. We are here spending our free time trying to help and if we have incorrect information we can not do it and waste a lot of time for nothing. – cybmeta Dec 23 '14 at 12:43
  • I confirm that loading wp-load-php, wp-config.php and wp-blog-loader.php at the same time generate the error. Remember that, as I said before, wp-config.php is loaded in wp-load.php and that wp-blog-header.php is loading again wp-load.php. Use only wp-load.php or, if you need the template engine, use only wp-blog-header.php. – cybmeta Dec 23 '14 at 12:52
  • Yes, sorry, I made the changes in the other question but I've some problems in my conexion and I forget see if the question has been edited (I saw your answers in my mobile and I didn't see the question again) – Marcos Dec 23 '14 at 12:55
  • I add others requires in my ajax (I put this in the question) but I'm not sure if this is the correct way @cybmeta – Marcos Dec 23 '14 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.