Hot answers tagged

42 votes

How to run a function every 5 minutes?

You can create new schedule times via cron_schedules: function my_cron_schedules($schedules){ if(!isset($schedules["5min"])){ $schedules["5min"] = array( 'interval' => 5*60,...
user avatar
14 votes
Accepted

How to create collections that are edited in admin?

I believe what you're referring to is called "Post Types". By default, WordPress has a complete post types you're already familiar with - post ( news / blog ), page ( Pages ), attachment ( Media ), ...
user avatar
  • 19.7k
7 votes
Accepted

wp_schedule_event not working?

Turns out I had to set the ALTERNATE_WP_CRON flag in wp-config.php to make this work: define('ALTERNATE_WP_CRON', true);
user avatar
5 votes
Accepted

Keyup events in tinymce editor not working

You can create a new plugin with the mce_external_plugins filter.. and link it to a js file. Then, in that file you can do your processing. function tinymce_init() { // Hook to tinymce plugins ...
user avatar
  • 1,089
4 votes

WP Cron Doesn't Execute When Time Elapses

For anyone protecting their (development) site from public access, HTTP Authentication can be the cause of WP Cron not functioning. In case it can help anyone, here is my list of things I did before ...
user avatar
  • 147
3 votes

How to capture the selection:toggle event fired by wp.media

I was able to cobble something together. I feel like there is a better approach to solving this, but that it might help to share my progress anyway. The main trick came from this answer by @Vladimir ...
user avatar
3 votes

How to run a function every 5 minutes?

If your site does get heavy traffic then you could try using set_transient() to run it (very approximately) every 5 minutes, eg: function run_every_five_minutes() { // Could probably do with some ...
user avatar
  • 4,328
3 votes

How to test wp_cron?

wp-cli is another way: Listing Events > wp cron event list +-------------------+---------------------+-----------------------+---------------+ | hook | next_run_gmt | ...
user avatar
  • 4,438
3 votes
Accepted

Why is wp-cron only executing on page visit?

It's not possible with just WordPress to schedule code to run in the background at a specific time. WordPress, like most (if not all) PHP web applications, only actually runs in response to a URL ...
user avatar
3 votes
Accepted

Pass argument to event hook

I would suggest first read the wordpress documentation about actions to understand how they work. Actions are aplit into two section, add_action and do_action do_action is the "location" ...
user avatar
2 votes

Scheduled events disappear from events queue

My solution for now is check every hour if it is running and if not reschedule it. I also remove this in deactivate etc. wp_schedule_event(time(), 'hourly', 'my_restart_schedule_if_failed'); ...
user avatar
2 votes

Create a custom event post

The easiest way to create a custom post type in WordPress is by using a plugin. This method is recommended for beginner because it is safe and easy. For example : Custom Post Type UI The problem ...
user avatar
  • 196
2 votes
Accepted

Show only the future event (Advanced Custom Fields)

You need a meta query. There's also documentation on ACF for querying dates. <?php $event = new WP_Query( array( 'post_type' => 'gacr-event', 'posts_per_page' => ...
user avatar
  • 35.7k
2 votes

How to run a function every 5 minutes?

You can trigger it in plugin activation instead of on each plugin call: //Add a utility function to handle logs more nicely. if ( ! function_exists('write_log')) { function write_log ( $log )...
user avatar
2 votes

How to fire jQuery after $(window).on('load')

It likely does not have to do with WordPress Core - in most cases this type of issue comes about when plugins conflict. I would suggest deactivating all your other plugins and trying a default theme, ...
user avatar
  • 8,746
1 vote
Accepted

How to add onclick event to widget image

I would use the Google Tag Manager firing options: Or Old school jQuery solution: function($){ $('.widget_class').click(function() { ga('send', 'event', 'Sidebar Image', 'Promo ...
user avatar
  • 1,561
1 vote
Accepted

WordPress Scheduled Event Request Blocking

Yes, WP Cron won't run if nobody visits your site. You can also run into the PHP execution time limits There are ways to mitigate this however: Manually ping the cron URLs via a real cron job using ...
user avatar
  • 53.3k
1 vote
Accepted

Manipulate post category after time

Your current function works pretty well, but it's hooked on to a post update hook so you need to actually edit/update a post for it to run. If you want the posts to be modified automatically after the ...
user avatar
  • 603
1 vote

Manipulate post category after time

The save_post hook passes the ID of the post to its callback function, so there's no need to use get_the_ID(). If you use wp_insert_post(), a new post will be inserted to database each time you save ...
user avatar
  • 14.7k
1 vote

Event-Driven Pattern vs MVC?

I will try to explain it simplest as i can: MVC Framework - Is a framework, that uses MVC software architectural pattern. This pattern sepatares logic in Controller, data in Models, and HTML code in ...
user avatar
  • 206
1 vote
Accepted

scrolltop always 0, can't trigger script

I guess body.scrollTop is deprecated in strict mode. Please use documentElement.scrollTop if in strict mode and body.scrollTop only if in quirks mode. So I would suggest you to use document....
user avatar
  • 1,633
1 vote

Display content based on an event

Your code runs on init which is well before the the_content filter is called. There is no reason you can't hook into it. It should be as easy as: add_filter( 'the_content', function ($content) ...
user avatar
  • 63.7k
1 vote

How to run a function every 5 minutes?

@johano's answer correctly explains how to set up a custom interval for WP cron job. The second question isn't answered though, which is how to run a cron every minute: In the file wp-config.php, add ...
user avatar
  • 546
1 vote

How to run a function every 5 minutes?

The Cronjob Scheduler plugin allows you to run frequent tasks reliably and timely without anyone having to visit your site, all you need is at least 1 action and a Unix Crontab schedule. It's very ...
user avatar
  • 113
1 vote

How to run a function every 5 minutes?

I'm afraid that other than waiting for someone to visit your site which runs a function, the only other option is to set up a cron job on your server using something like this https://stackoverflow....
user avatar
1 vote
Accepted

Archive by custom post type and custom date field

Thanks to Milo for helping me through this. Here is the code that worked for me. function custom_events_query( $query ) { if ( $query->is_main_query() && $query->is_archive &&...
user avatar
  • 141
1 vote

How to prevent the scheduling of the same event on the same day

Personally, I would have just one (WordPress) cron event that fired daily. All queued emails are stored in a table/option. Now all you do in your cron handler is grab the next email in the queue, ...
user avatar
  • 35.7k
1 vote

Wordpress Media Uploader events

You should got a class for that button Try to find it and, if exists, you can fire event i.e using jQuery: jQuery(".button-class").click(...);
user avatar
1 vote

Wordpress Media Uploader events

I don't think there is. You will have to use some local (browser-based) Javascript code to attach a function to the on-click event of the button. (Not a Javascript expert, but perhaps this will point ...
user avatar
1 vote

the 'save_post' event triggers when I want to start a new post

You can simplify your save handler by checking if the POST variable is set. If it isn't, no need to handle the request: function save_files( $post_id, $post ) { if( ! isset( $_POST['...
user avatar
  • 35.7k

Only top scored, non community-wiki answers of a minimum length are eligible