I am working on a wordpress website. I want to do some updates on the products via a cpanel cron job. for that I created a new file at the root /public_html/update-products.php and on cpanel added the cron job command:
/usr/local/bin/php /home1/blahblah/public_html/update-products.php
my problem is that I want to use wordpress functions in this file like get_option, update_option, update_post_meta ... etc
what file from wordpress should I include at the top of my file. I tried to include the index.php file itself so I can use such functions.
here is the file code (update-products.php)
require_once __DIR__ . '/index.php';
require_once __DIR__ . '/wp-content/plugins/citycenter-products/includes/api.php';
$last_update_info = get_option(DS_CITYCENTER_PRODUCTS_LAST_UPDATE_COMPACT_OPTION);
$data = array('type' => 'compact');
if ($last_update_info) {
$data['from_datetime'] = $last_update_info['date'].' '.$last_update_info['time'];
}
$result = update_citycenter_products($data);
$last_update_info = array(
'type' => 'compact',
'date' => date('Y-m-d'),
'time' => date('H:i:s'),
'total' => $result['total'],
'updated' => $result['updated'],
'added' => $result['added'],
);
update_option(DS_CITYCENTER_PRODUCTS_LAST_UPDATE_COMPACT_OPTION, $last_update_info);