Initialize WordPress environment to use in a real cron script
You can use real cron to trigger WP cron – by fetching wp-cron.php file from root (snippet from quick google search). That will take care of environment and everything.
You can use real cron to trigger WP cron – by fetching wp-cron.php file from root (snippet from quick google search). That will take care of environment and everything.
Today i got exactly the same behaviour when adding a custom post type. I also noticed some admin post search tools stopped working. My debug_log showed exactly the same notice. The problem turned out to be some text before the <?php opening tag (top file) were I register the CPT. Example some text here<?php /** … Read more
url_to_postid(wp_get_referer()) will give you the ID of the referring page/post if you were referred from a page or a post. It won’t work if referred from some other types of pages, like archives. You will then need to retrieve the categories for the ID to see if they match. I would strongly consider passing a … Read more
If you installed WordPress Multisite starting with version 3.0 to 3.4.2, you’ve got the correct .htaccess file contents. However, if you started with a newer version (3.5 or higher)—and I’m assuming you did, if you’ve just installed WordPress Multisite recently—your .htaccess file should look like this: RewriteEngine On RewriteBase / RewriteRule ^index\.php$ – [L] # … Read more
Use the defines to make it pick the site you want it to pick. You can define these four to setup the $current_site values properly: DOMAIN_CURRENT_SITE, PATH_CURRENT_SITE, SITE_ID_CURRENT_SITE, BLOG_ID_CURRENT_SITE. If you check the wpmu_current_site() function in ms-load.php, you’ll see that it uses those to create the $current_site global. You may or may not have to … Read more
wp_loaded fires for both the front-end and admin section of the site. This action hook is fired once WordPress, all plugins, and the theme are fully loaded and instantiated. Since you’re checking for plugin updates, it might be best to hook into admin_init instead of wp_loaded — assuming you want to know if a user … Read more
Yeah $wpdb2 = new wpdb(‘dbuser’, ‘dbpassword’, ‘dbname’, ‘dbhost’); // get 10 posts, assuming the other WordPress db table prefix is “wp_” $query = “SELECT post_title, guid FROM wp_posts WHERE post_status=”publish” AND post_type=”post” ORDER BY post_date DESC LIMIT 10″; $someposts = $wpdb2->get_results($query, OBJECT); foreach($someposts as $somepost) echo “<a href=\”{$somepost->guid}\”>{$somepost->post_title}</a><br />”; Another way is to use the … Read more
The shortest way is to load wp-load.php and abort the loading of the template engine (Note: You couldn’t do that, if you’d be loading the header file, like you see it on many sites in the interweb). # No need for the template engine define( ‘WP_USE_THEMES’, false ); # Load WordPress Core // Assuming we’re … Read more
muplugins_loaded is the earliest hook. Depending on your wordpress setup, you may not have any plugins in the MU_PLUGINS directory. In that case this hook may not fire. The next best hook to trigger is plugins_loaded. RESOURCES WordPress Codex – Action Reference List Q/A: How to get WordPress’ hook run sequence? Q/A: Make sense of … Read more
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; } } … Read more