I came up with following solution. The script have to start with the following code.
<?php
if( php_sapi_name() !== 'cli' ) {
die("Meant to be run from command line");
}
function find_wordpress_base_path() {
$dir = dirname(__FILE__);
do {
//it is possible to check for other files here
if( file_exists($dir."/wp-config.php") ) {
return $dir;
}
} while( $dir = realpath("$dir/..") );
return null;
}
define( 'BASE_PATH', find_wordpress_base_path()."https://wordpress.stackexchange.com/" );
define('WP_USE_THEMES', false);
global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header;
require(BASE_PATH . 'wp-load.php');
Related
Related Posts:
- Is it possible to get post metadata of referring page?
- Initialize WordPress environment to use in a real cron script
- Creating a Dynamic Path to wp-blog-header.php
- Problem accessing wp-load.php
- How to load wordpress environment without loading the template?
- WordPress function gives different results outside vs inside PHPUnit test
- How to avoid wp-load.php within a PHP/CSS file?
- How to efficiently load and use the wordpress API from outside the original structure
- Best way to load WordPress Bootstrap
- Check user logged in from outside of WP folder
- wp-load.php not working
- WP_load, shortinit for wordpress Ajax
- WordPress Nexus Theme front-end editor broken because cannot find wp-load.php [closed]
- Fetching latest posts from 2 different WP installations
- Loading wp-load.php in an external PHP file throws unknown error
- Which position is after `wp-load.php`?
- Exploiting WordPress Core Functionality for Development
- How to include wp-load.php and have all plugins load as well
- content of the page is not displaying getting empty page [closed]
- Error unable to access jarfile C:\Jar
- How to pretty print XML from the command line?
- Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools)
- Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools)
- How do I copy a folder from remote to local using scp?
- What does cmd /C mean?
- Why do JVM arguments start with “-D”?
- How do I import an SQL file using the command line in MySQL?
- Command Prompt “Net View System Error 6118”
- Windows 7 Symbolic Link – Cannot create a file when that file already exists
- How to change the output color of echo in Linux
- Recursively find all files that match a certain pattern
- Diff command along with Grep gives “Binary file (standard input) matches”
- How do I make a python script executable?
- What is cp: cannot stat error in Unix, I get this error when trying to copy thing from one folder to another
- How do I set a variable to the output of a command in Bash?
- Run C++ in command prompt – Windows
- Run R script from command line
- How to edit a py file from terminal?
- How to colorize diff on the command line
- How to count lines in a document?
- How to easily print ascii-art text?
- Command Prompt Error ‘C:\Program’ is not recognized as an internal or external command, operable program or batch file
- Run Command Prompt Commands
- What is %0|%0 and how does it work?
- npm install multiple package names
- Install oAuth PECL error: Cannot install, php_dir for channel “pecl.php.net” is not writeable by the current user
- Command prompt won’t change directory to another drive
- ‘ssh’ is not recognized as an internal or external command
- Timeout a command in bash without unnecessary delay
- Delete .DS_STORE files in current folder and all subfolders from command line on Mac
- Run function from the command line
- Access WordPress API Outside of WordPress (command-line PHP)
- wp-cli displays php notices when display errors off
- Displaying content from one WP site on separate WP site
- Is it possible to export WordPress from command line?
- When is wp_loaded initiated only with admin or only when user enters the site or both?
- Where/how are categories stored?
- What is the best way to load the WP environment in a subdomain of my multisite WordPress install?
- How do I pass an array as an argument to a WP-CLI command?
- Trying to avoid including wp-load.php
- Create a post variable processing page
- external wordpress pages using wp-blog-header
- How to determine wordpress base path when wordpress core is not loaded
- Looking for a better way to handle an ajax script that pulls in post data on click
- How to disable XML-RPC from Linux command-line in a total way?
- Get current user data from external PHP page
- wp_enqueue_style with style.php and WordPress functions
- Do you have to have command line access to use Subversion with WordPress?
- wp-load Without Loading the plugins
- Include CSS with PHP without including wp-load?
- Error updating WP-CLI
- Accessing the database from a plugin outside of action hooks
- Issue using wp-load.php in WordPress Plugin Development
- How to retrieve text only from a post using WP CLI?
- wp search-replace (not executing)
- Cron job script – loading wordpress system fails
- Other than WP-CLI, is there a way to install WordPress via the command-line?
- Programmatically inserting post through URL – when including wp-load.php, it’s redirecting to wp-admin/install.php
- Running custom defined WP-CLI commands without WordPress installation present
- Load wordpress content in other domain
- Using wpdb without loading all plug-ins via wp-load.php
- How can I list all installed plugins/themes/versions from CLI/API?
- Use wp-load() and wp_head() to render a page’s header outside of WordPress
- Take control of WordPress before functions.php
- wp-load.php redeclares classes
- I need a standalone script in web root but still have access to the database
- Bulk update published posts date randomly using wp-cli?
- How to add a custom filter (by coding) before access one wordpress page ? And where to call the custom filter?
- Hook from plugin doesn’t fire up from external PHP script
- Using the WP CLI to output the HTML results of calling a post?
- WordPress custom php script to match standard page layout
- Getting Fatal error: Uncaught Error: Call to undefined function plugin_dir_path() when linking to another file within my wordpress plugin
- How to remove all plugins, posts, pages, and inactive themes in one line with wp-cli? WordPress bloatware removal
- bash script wp-cli search-replace 0 replacements, but command-line 3000+
- Avoid ‘uploads’ 777 permissions: Potential threat or clean solution?
- Rewritten URL not loading WordPress environment
- Get wp-load.php PATH with wp_localize_script and JavaScript for plugin
- To call hook on a php external file
- wordpress login blank screen [closed]
- Bulk delete media by year