wp_delete_auto_drafts() deletes links in menus

This is what normal query run by wp_get_associated_nav_menu_items() looks like: SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.id = wp_postmeta.post_id ) WHERE 1 = 1 AND wp_posts.post_type=”nav_menu_item” AND (( wp_posts.post_status <> ‘trash’ AND wp_posts.post_status <> ‘auto-draft’ )) AND (( wp_postmeta.meta_key = ‘_menu_item_object_id’ AND Cast(wp_postmeta.meta_value AS CHAR) = ‘3111’ )) GROUP BY wp_posts.id ORDER … Read more

Cron schedule interval through plugin options?

Yes, in my opinion that’s exactly the right way to extend the default schedule timings. I would be a little more informative with the display value but I think that is only example code. However, one important thing should be taken into account. The default WordPress schedule implementation that is invoked as a side effect … Read more

Where in the page load code is wp-cron triggered?

The WordPress cron is run by the wp_cron() function, which is hooked to run on the init hook, which runs on every page load. wp_cron() is defined in wp-includes/cron.php and hooked in wp-includes/default-filters.php. The wp_cron() function kicks off a wp_remote_post() request to /wp-cron.php. Some server configurations prevent scripts sending a request to the same domain … Read more

Automated mark posts as featured every day

OK, so first of all you’ll need to add your own WP_Schedule event: add_action( ‘wp’, function () { if (! wp_next_scheduled ( ‘mark_posts_as_featured_event’ )) { wp_schedule_event(time(), ‘daily’, ‘mark_posts_as_featured_event’); } } ); function mark_posts_as_featured_event_callback() { // if there are sticky posts in our CPT, unstick them $sticked_post_ids = get_option( ‘sticky_posts’ ); if ( ! empty ) … Read more

How to set up WP Cron in this scenario

First things first: Say hello! to $wpdb The wpdb Class is what you take to interact with the database on it’s most basic level. Forget all those mysql_* functions, when it comes to WordPress. The core has a nice wrapper, that makes most things pretty safe for you (hint: SQL-injections and other bad boys). Or … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)