简体   繁体   中英

How to call WordPress PHP file using external js file

I have added custom PHP file in WordPress directory and added following line to use WordPress functions:

require ('../wp-blog-header.php');

Now I am able to use WordPress functions but unable call this file from javascript in ajax.

When I removed following line then I am able to call this file:

require ('../wp-blog-header.php');

Please suggest how can I solve this issue.

looks like this is standard behavior of WP

change

require ('../wp-blog-header.php');

to this line

require(dirname(__FILE__) . '../../wp-config.php'); //path to Your wp-config.php file

$wp->init();
$wp->parse_request();
$wp->query_posts();
$wp->register_globals();
//$wp->send_headers();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM