So I have this PHP file which has an Ajax call of a file called, let’s say test.php. This test.php requires two files, this is how they’re called:
require('../folder1/folder2/header.php');
require('../wp-blog-header.php');
So, if I remove the second line of code, it works just fine, but as soon as I add that second line it no longer works, the Network tab in console gives me 404.
The wordpress file and the folder1 are in the same directory.
Probably you going wrong way of AJAX in wordpress. Try following code not need include any file.In functions.php file
and client side your ajax call should following:
First, Don’t use relative path(s).
Check out these Questions, they’re described nicely in terms of Paths.
Second, Don’t use
wp-blog-header.php
just like that. If you really want WordPress Environment to work inside your test.php file, Then it’ll be better if you either write code as a Plugin or write your code in function.php.Reference Links
Third,
wp-blog-header.php
should be called before any file you are requiring in your code. So that way WordPress environment loads into that file as well. Otherwise, WordPress functions will not work properly.Check
index.php
inside WordPress root folder.wp-blog-header.php
is the first file required to load WordPress Environment.index.php (At WordPress Root Folder)
If you’re receiving a
404
error it means that is not exactly a php error that is ocurring. One of this files (probablywp-blog-header.php
) are trying to redirect you to another page that is no longer available (e.g: this scripts are redirecting you using anheader('Location: ...')
to a page that is not available).Check the contents of the files and look for a redirection of this type. An inclusion error do not brings to you a
404
alert, it should brings aFATAL ERROR
.Additionaly…
Always when you use
require()
function, try to use absolute paths. Relative paths causes a lot of problems when you’re using a third party code.Use
instead of