Hi

I have two scripts set to run at different times Monday- Friday that are meant to change the value of a Metabox custom field on a metabox settings page.

If I place these scripts in a codeblock on a template they execute as soon as the template is loaded, proving that the scripts themselves work.  This means that the issue has to be with the way that I have configured the timing, which I’m pretty certain is following your own documentation, or there has to be another reason why these aren’t run.

Having these on a timer is vital as it should assist in setting some key functionality on the site. I have attached the scripts to this message and hopefully you’ll be able to identify if I have either made a configuration error or suggest some other way to get them to actually run at the intended time.

Many thanks

 

 

Dom

I don’t know why but it seems that I can’t upload files so this is the script:

 

<?php
    $option_name = ‘marketplace’;
    $field_id = ‘market_place’;
    $myvalue = ‘open’;
    rwmb_set_meta( $option_name, $field_id, $myvalue, [ ‘object_type’ => ‘setting’ ] );
?>
The script is set up in the following way’
Trigger location:   Conditions
Script Location:  php
Template: All
Schedule:  Days
Days: Mondays, Tuesdays, Wednesdays, Thursdays, Fridays
Script Duration:  Time
Start at specific time: 18:00

End at specific Time:  18:15

The other script is more or less the same;

<?php
    $option_name = ‘marketplace’;
    $field_id = ‘market_place’;
    $myvalue = ‘closed’;
    rwmb_set_meta( $option_name, $field_id, $myvalue, [ ‘object_type’ => ‘setting’ ] );
?>
The settings are exactly the same , save for the start and end time set for 22:00 and 22:15 respectively

7 responses to “Can you see why these scripts may not be running at the allocated times”

  1. cmsexpertss says:

    Hi Dom,

    Thank you for contacting us.

    Have you checked/matched your server/local time that is shown on the code block settings in Scripts Organizer and while you are checking it?

    Also, please share your site WP access so we can check it as without having actual scenario, we cannot really comment what’s happening.

    Regards,
    Muhammad Osama

  2. Dom says:

    Hi Muhammad

    I have setup an admin account for you at the site:

    UserName = MO
    Password = 5sm5UMCrsk48Q!JB7EWEx5eB

    the site address is https://staging.hastingsdirectfish.co.uk/wp-login.php

    This help file on Metabox explains the logic behind setting settings page values.
    https://docs.metabox.io/rwmb-set-meta/

    The two original scripts were Open Market Place and Close Market Place.

    The help file suggests that it ought to be an init action so I also tried that in a different script, Initialise Market place.

    None of these appear to run at the appointed time.

    I’d welcome any thoughts that you have on the matter.

    Many thanks

    Dom

  3. cmsexpertss says:

    Hi Dom,

    Thank you for providing me access. I debugged it and after research I found this article https://metabox.io/support/topic/rwmb_set_meta-in-for-settings-page-field/ and if you see the last comment then it seems the issue is on Metabox end that they have issue in rwmb_set_meta function, its not saving settings.

    Regards,
    Muhammad Osama

  4. Dom says:

    Hi Muhammad

    Thank you for getting back to me.

    I take it then that the code clocks are running and I did set thenm up correctly? It’s just a tad unfortunate that I happened to try these out setting a metabox settings page using a function that just happens to have a bug!

    Regards

    Dom

  5. Dom says:

    Hi Muhammad

    I referred back to to the link that you provided and substituted the the code I had for rwmb_set_meta() with the code suggested in the article, and it worked.

    I then asked very specifically of Metabox support if they had fixed the rwmb_set_meta() function such that it saved data and they replied that they had suggesting the following code:

    add_action( ‘init’, function() {
    $option_name = ‘my_option’;
    $field_id = ‘my_field’;
    $value = ‘My custom value’;
    rwmb_set_meta( $option_name, $field_id, $value, [ ‘object_type’ => ‘setting’ ] );
    }, 99 );

    Now as it happens I had tried this in a code clock (which you may have seen when you looked at my site and it definitely didn’t work, however running the following in an oxygen code block on a template does.

    $option_name = ‘my_option’;
    $field_id = ‘my_field’;
    $value = ‘My custom value’;
    rwmb_set_meta( $option_name, $field_id, $value, [ ‘object_type’ => ‘setting’ ] );

    You may also have noticed that I had experimented with WP Control, a plugin designed to show you which cron jobs are running and also to add cron jobs. Interesting I added two cron jobs using

    $option_name = ‘my_option’;
    $field_id = ‘my_field’;
    $value = ‘My custom value’;
    rwmb_set_meta( $option_name, $field_id, $value, [ ‘object_type’ => ‘setting’ ] );

    and they worked. So this suggests that Metabaox did fix the issue.

    Now as it happens I would far rather use scripts organised because it is more flexible, especially when it comes to running code on separate days .

    May I ask a few questions about what your ‘timed’scripts are.

    Are you creating cron jobs? I presume not because I would have expected to see them listed in wp control, and I suspect that that also explains why the Metabox support suggested code using the init hook didn’t work either. What are your timed events hooking into?

    I have some quite complicated stuff that I would like to do with this site, and I suspect that knowing what you’re actually hooking into may be useful. Ironically I could do this very easily in Don Net but that is simply because it’s where my own expertise lies and I still have a lot to learn about web development which i am keen to do (to that end some more technical information and examples in your documentation would be very welcome).

    This leads nicely to another question. In the documentation it states clearly that a timed event needs both a start time and an end time. In this particular case I’m setting a single solitary value which will take miliseconds. Let’s say I have a start time of 8:00 am doest the end time have to be later (so it would have to be 8:15 as you only have 15 minute slots) or could the end time be the same as the start time. The documentation doesn’t say (a good example of where it lacks in some crucial details).

    It would be nice if it were possible to select single minutes on the hour rather than the fifteen minute ones there are at the moment.

    Once again thank you for your help. Access to the site is still available should you wish to look at it again. It’s purely experimental so you won’t really break anything if you want to experiment.

    Regards

    Dom

    • cmsexpertss says:

      Hi Dom,

      Thank you for providing detailed information.

      Regarding, your question, we are not adding any cron jobs the reason is in cron jobs you don’t have page attributes like post type, taxonomy etc available.

      Regarding time options, for now we are only providing 15 minutes time difference, we may add minutes option later, but setting start and end time same would never work.

      Regarding your code, I gave it another try and as you want the field to be set as long as the time gets matched, so I set it to run “everywhere” and made some priority change in hook and it worked. The code block in which I made change is “Open Market Place”, so please try it and let me know if it fixed your issue.

      Regards,
      Muhammad Osama

Leave a Reply to cmsexpertss Cancel reply

Your email address will not be published.