Xaedes solution in https://wordpress.stackexchange.com/a/76466/107596 works quite well:
<?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 Posts:
- Running WP Cron on multisite the right way
- Converting timestamps to local time with date_l18n()
- What is in media-template.php, and how does it work?
- wp_delete_auto_drafts() deletes links in menus
- How to run multiple Async HTTP requests in WordPress?
- Change Password Hint
- Initialize WordPress environment to use in a real cron script
- How to correct schedule my event weekly with wp_schedule_event()
- Best way to extends core classes in theme?
- Multiple wp_schedule_event cron jobs in plugin cause multi-execution
- How to make sure that only one wp_cron() runs at a time?
- wp_delete_auto_drafts() deletes links in menus
- Question about the template-loader.php file
- How does WP detect format type (and can I make use of this)?
- Does wp-cron runs all tasks scheduled at same time together or one after other?
- Remove annoying WP Adminbar CSS
- How do I implement a .diff changeset from core.trac.wordpress.org locally?
- Huge debug.log because of “undefined offset in media.php”
- export a csv file from the database with a cronjob
- Cron events are disappearing, or cannot be updated in WordPress
- WP CRON duplicate wp_insert_post with has < and > tag
- How wp-cron can run in background if PHP is single threaded?
- WP Cron job timeout issues
- running wp-cron.php using php not wget
- Best way to schedule daily change in CSS parameter
- Are all hooks/functions tied to Kses meant for sanitization?
- Location of core code for database connection and get_header
- Scheduling an event inside plugin class is not working
- Large WordPress CRON job
- How to Schedule Cronjobs for start of every month and year
- Admin submenu issue with PHP not detecting two strings as equal
- WordPress cron is running with previously set time intervals and not the updated one
- Usage of var keyword in the core
- Can/should we delete wordpress cron jobs with no action?
- Use wp_head hook on template page
- Setting up a cron job to auto update a custom field
- Load WordPress core but with specific plugins
- Multiple cron jobs vs daily cron job doing multiple things? Which one yields better performance and scalability?
- post_exists stops working in a scheduled event
- CRON job to update wp_usermeta value each day or week based on server time
- Cron not sending wp-mail()
- Automatically delete posts one by one depending on published time
- Php cron job (wp-cron) not working
- Use WP Cron to Clear a Page Cache?
- Custom WordPress Core upgrade through wp-cli
- Update all posts in custom post types with wp_cron()?
- Sort WooCommerce data with WP-CRON?
- How do I routinely extract the thumbnail of the most recent post?
- Break a WordPress function to run in patches and re-continue
- WPMU schedule doesn’t execute actions
- How to execute add_action() function from custom plugin to Crontrol plugin or do_action()?
- How to avoid timeout waiting for output from CGI script?
- How can precision be improved for the debug log timestamp?
- understanding wp_next_scheduled
- Error resetting database index using ALTER TABLE in $wpdb->query
- Background Tasks in a WP Cronjob?
- change div text and link for logged in users
- Image Upload “exceeds the maximum upload size for this site”, but php.ini is correct
- simple wordpress ajax plugin not working when not logged in
- Audio Player not loading when the content is loaded through Ajax, MediaElement.js no applied
- A Specific Blog post to be assigned as the landing page of my wordpress blog
- How to convert objects into arrays
- How to periodically scrape and cache strings from remote txt files. – My First Plugin
- Randomly Assign an Image’s Alt Text Based on Data From Post
- How to add seperate classes to no-search-result and found-search-result pages on wordrpess search – is_search()
- Edit incorrect password message WordPress
- A non-numeric value encountered in /wp-includes/functions.php on line 68
- XAMPP-VM Mac OS Mojave wordpress debugging using XDebug
- How to get original custom taxonomy slug after the slug has been rewritten?
- WordPress & Fastcgi proper setup?
- Checkbox doesn’t stay checked, conten
- How do I Import / Upload Files with jQuery AJAX?
- Variable not staying set
- How to set the WordPress logo programmatically with PHP
- How to pass a variable to get_template_part that’s updated every time the template part is called?
- $_SESSION variable not saving on page refresh or new page
- Form search query – displaying ACF “Post Object” field as results
- Extract links from content
- get_page_template_slug returns incorrect path
- Sorting dynamic select/dropdown for Contact Form 7 of Modern Tribe Events posts
- Noindex subscriber author page
- Action Hook Inside WordPress Plugin Shortcode
- Changes made on php.ini have no effect on wordpress
- Using php code inside style tag
- How to pass values from one function to the other using an array variable
- How to change the content width using php?
- get_the_author_meta( ‘ID’ ) just return 1
- Site title not showing. Please help me
- Email always ends up in spam
- How to link featured images in single.php for only non-logged-in users?
- Target a specific container to style on WordPress storefront theme
- Search the post using get_search_form()
- Need to Echo A Url path to show on a wordpress page
- How can I move the posted-on date above the post and below the entry-header?
- ‘posts_per_page’ in costum page type
- how to exclude admin page from add_rewrite_rule in wordpress
- How to use ‘depth’?
- Pagination on Custom Loop
- Query Concatenation
- Link a lightbox thumbnail to a post instead of opening the lightbox