Setting a settings page option programatically.

Support MB Settings Page Setting a settings page option programatically.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #33191
    dom@viewtolearn.co.uk[email protected]
    Participant

    Hi
    Using Oxygen Builder 3.9.

    I have the following code which perfectly changes a text field on my settings page when it is run in a code block on a page.

    <?php

    $option_name = 'marketplace';
    $field_id = 'market_place';
    $myvalue = 'closed';
    rwmb_set_meta( $option_name, $field_id, $myvalue, [ 'object_type' =&gt; 'setting' ] );
    

    ?>

    In reality I need this to run at a set time every day, and thus far I have been unable to do that using dplugins script organiser and a timed script execution.

    I thought I'd try another approach and have it fire when a countdown timer ends (as the logic I wish to execute on the site involves them both this seems sensible. With that in mind I know the following javascript will pickup the countdowm timer ending.

    jQuery(document).ready(function($) {

    if ($ ('html'). attr ('ng-app') == 'CTFrontendBuilder') return; 
    
    
    const myCountdownTimerSelector = '#-countdown-timer-15-26'; /* ID of countdown timer element */
    
    const countdownTimer = $(myCountdownTimerSelector).find('.oxy-countdown-timer_inner');
    
    
    // do something when countdown finishes
    countdownTimer.on('finish.countdown', function() {
    
        // code inside here runs when the countdown hits zero.
                //What is best way to change metabox customfield value here?
    
    });
    
    
    // set a new date/time programatically
    //countdownTimer.countdown('2022-03-12 11:31:30');
    
    
    // control the timer ('pause, resume, start, stop')
    //countdownTimer.countdown('pause');
    

    });

    My knowledge of mixing php and javascript is scant at best and I seem not to be able to effect the change I need to to the custom field.

    Can you tell me if it's even possible to do it this way?

    Many thanks

    Dom

    #33202
    Long NguyenLong Nguyen
    Moderator

    Hi Dom,

    If you want to run a function every day, you can use the WP Cron. Please follow this topic to know how to set up a cron job https://stackoverflow.com/questions/49954871/setting-up-a-cron-job-corectly-within-wordpress-plugin

    Remember to hook the function to init action with priority later than 20. Refer to the documentation https://docs.metabox.io/rwmb-set-meta/

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.