Support

Account

Home Forums Backend Issues (wp-admin) Real cron job can't see fields from options page

Helping

Real cron job can't see fields from options page

  • Hi, i need to create real cron job, i’m loading wp environment with:
    require_once( $parse_uri[0] . 'wp-load.php' ); //$parse_uri[0] = earlier parsed uri, works
    and then i’m calling one of my functions after checking if plugin was initialized:

    if(in_array( 'omapi/omapi.php', (array) get_option( 'active_plugins', array() ) )) {
    	require_once(sprintf("%s/omapi-func.php", dirname(__FILE__)));
    	$omapi = new omapi_Func();
    	$omapi->get_offers();
    }

    When i’m launching this from my browser, all works fine, but when server is doing cron job, most works, updating posts, comparing custom fields etc, but it seems script can’t get custom fields registered in options page (registration is hooked to __construct of my main plugin file with add_action('init')

    I don’t get what is the problem, i even tried to add check if there is field registered in options and if not i called registration function, but that haven’t changed anything.

    After i’m changing cron to wget -q -O with url instead php with relative path cron launches correctly, but i want it to be relative.

  • Hi, Post is dead, but it is on the first page of google when you type “acf cron get_field options page”, so for future seekers, there is a solution.

    I had similar problem. I can’t get fields values by get_field in function fired by cron. So, after research in acf and polylang code I used:

    $locale = 'en_GB'; // You can use get locale function, for eg from polylang: pll_get_post_language( $post_id, 'locale' )
    get_field($name, 'options_'.$locale);

    instead of

    get_field($name, 'options');

    And it works.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Real cron job can't see fields from options page’ is closed to new replies.