$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Problem accessing wp-load.php|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Problem accessing wp-load.php

matteradmin9PV0评论

I'm writing a standalone script for Wordpress so I can display things like the username on a page outside of Wordpress.

My method so far is to try to include or require wp-load.php in my script directory. I've tried

chdir ( ".." );
include "wp-load.php";

as well as absolute paths to the web root where Wordpress is located for both the chdir and the include. I don't get any errors but wp_get_current_user() always returns empty.

If I move my script up a level to the same folder with Wordpress it works fine. How can I include wp-load.php and keep all of the files in my subfolder?

EDIT: file structure

  • public_html (wordpress is installed here so wp-load.php is also here)
    • myScript (directory)
      • script.php
      • This is where I try to use chdir ( ".." ) or include ( "../wp-load.php" ) without success

I'm writing a standalone script for Wordpress so I can display things like the username on a page outside of Wordpress.

My method so far is to try to include or require wp-load.php in my script directory. I've tried

chdir ( ".." );
include "wp-load.php";

as well as absolute paths to the web root where Wordpress is located for both the chdir and the include. I don't get any errors but wp_get_current_user() always returns empty.

If I move my script up a level to the same folder with Wordpress it works fine. How can I include wp-load.php and keep all of the files in my subfolder?

EDIT: file structure

  • public_html (wordpress is installed here so wp-load.php is also here)
    • myScript (directory)
      • script.php
      • This is where I try to use chdir ( ".." ) or include ( "../wp-load.php" ) without success
Share Improve this question edited Dec 18, 2018 at 6:46 scottinthebooth asked Dec 18, 2018 at 6:05 scottintheboothscottinthebooth 311 silver badge3 bronze badges 3
  • and please tell me the where you exactly include the wp-load.php – user147874 Commented Dec 18, 2018 at 6:21
  • did you got the result @scottinthebooth ? – Tejas Gajjar Commented Dec 18, 2018 at 11:35
  • I was not able to get this to work. I ended up just converting the script to a full plugin which solved the problem (if I'd realized how simple that was I would have started that way) – scottinthebooth Commented Dec 19, 2018 at 23:10
Add a comment  | 

2 Answers 2

Reset to default 1

try this i hope this work.

$parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] );    
require_once( $parse_uri[0] . 'wp-load.php' );

Use this to include

<?php include '../wp-load.php'; ?>

that will give you the wp-load.php file ../ is usually use for get path of last folder.

hope this helps you and also let me know the result.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far