Answer the question
In order to leave comments, you need to log in
Why writes that the path is not correct?
Hello, I'm making an ajax request for my site, and a problem has arisen: I have require in functions.php for my file with ajax requests
require get_template_directory() . '/inc/ajax.php';
function load_works() {
$args = unserialize( stripslashes( base64_decode( $_POST['query'] ) ) );
$args['paged'] = $_POST['current_page'] + 1;
query_posts( $args );
if ( have_posts() ) :
while ( have_posts() ): the_post();
// echo get_the_title();
require '../template/items-work.php';
endwhile;
endif;;
wp_die();
}
Answer the question
In order to leave comments, you need to log in
Because the path is specified not relative to the file in which the call to the require function is located, but relative to the current directory. For example, if the user called the script https://domain.name/a/b/c.php, then the current directory will be $_SERVER['DOCUMENT_ROOT'].'/a/b' and all relative paths will be built from it, regardless of the depth of nesting of included files, and not relative to included files.
If you want to specify a path relative to your file, regardless of the current directory, you can use the __DIR__ constant, for example.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question