I want to run wp_query on a separate php file for an ajax call

前端 未结 4 404
难免孤独
难免孤独 2021-01-03 00:43

For example:






        
相关标签:
4条回答
  • 2021-01-03 00:56

    You have to make the page that ajax calls a template page. Make a new page in your blog and assign the template. no headers no includes.

    0 讨论(0)
  • 2021-01-03 00:56

    You have to include the file that has the Wordpress functions located on the main directory of the Wordpress Installation:

    define('WP_USE_THEMES', false);  
    require_once('../../../wp-load.php');
    

    ../../../ = path to the main directory on your installation

    I found a nice tutorial about this here.

    0 讨论(0)
  • 2021-01-03 01:14

    This worked for me, maybe it will help someone else.

    My situation is I have a js file that uses getScript. In that script i have a bunch of .load() calls to a php file. At the top I place this.

    if (file_exists("../../../wp-load.php"))
        {
        require_once("../../../wp-load.php");
        }
    

    Change the ../ to how ever many directories your wp-load file is up.

    Edit - Using WP 3.4.1

    0 讨论(0)
  • 2021-01-03 01:19

    You can turn the template engine off and then include the header.
    // Include WordPress
    define('WP_USE_THEMES', false);
    require_once('PATHHERE/wp-blog-header.php');

    0 讨论(0)
提交回复
热议问题