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]
- “No such file or directory” but it exists
- Error unable to access jarfile C:\Jar
- Node.js version on the command line? (not the REPL)
- 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 to find which version of TensorFlow is installed in my system?
- How do I copy a folder from remote to local using scp?
- What does cmd /C mean?
- How do I parse command line arguments in Bash?
- What does cmd /C mean?
- syntax error when using command line in python
- https connection using CURL from command line
- syntax error when using command line in python
- How to install JQ on Mac on the command line?
- Using multiple delimiters in awk
- Create an empty file on the commandline in windows (like the linux touch command)
- How do I import an SQL file using the command line in MySQL?
- Why do JVM arguments start with “-D”?
- How do I import an SQL file using the command line in MySQL?
- How to reload .bash_profile from the command line?
- What is the purpose of “&&” in a shell command?
- Angular – ng: command not found
- How to run SQL script in MySQL?
- Mysql: Setup the format of DATETIME to ‘DD-MM-YYYY HH:MM:SS’ when creating a table
- How can I pass an argument to a PowerShell script?
- Command Prompt “Net View System Error 6118”
- Windows 7 Symbolic Link – Cannot create a file when that file already exists
- mkdir’s “-p” option
- 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
- What is cp: cannot stat error in Unix, I get this error when trying to copy thing from one folder to another
- fatal: This operation must be run in a work tree
- Run R script from command line
- How to edit a py file from terminal?
- How do you input command line arguments in IntelliJ IDEA?
- How do I parse command line arguments in Java?
- How to colorize diff on the command line
- How to colorize diff on the command line
- How can I find out if I have Xcode commandline tools installed?
- Python not working in the command line of git bash
- How to count lines in a document?
- What is the reason for the CD /D switch in Windows cmd?
- Running Command Line in Java
- 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
- phpmyadmin #1045 Cannot log in to the MySQL server. after installing mysql command line client
- git undo all uncommitted or unsaved changes
- Run Command Prompt Commands
- What is %0|%0 and how does it work?
- npm install multiple package names
- How to recursively download a folder via FTP on Linux
- Install oAuth PECL error: Cannot install, php_dir for channel “pecl.php.net” is not writeable by the current user
- Difference between $? and $LastExitCode in PowerShell
- Command prompt won’t change directory to another drive
- ‘ssh’ is not recognized as an internal or external command
- How to stop (and restart) the Rails Server?
- How to compile C program on command line using MinGW?
- how to empty recyclebin through command prompt?
- 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
- What is the correct way to use WordPress functions outside WordPress files?
- What is the very earliest action hook you can call?
- Access WordPress API Outside of WordPress (command-line PHP)
- Determining WordPress’ Version from the Host’s Command Line?
- How to load WordPress on non WP page?
- Running WordPress on the Command Line – Turn off Delayed Output?
- wp-cli displays php notices when display errors off
- How To Export/Import WordPress (MySQL) Database Properly Via Command-Line?
- 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?
- How to use command ‘wp post create’ in wp-cli properly?
- Where/how are categories stored?
- What is the best way to load the WP environment in a subdomain of my multisite WordPress install?