Template Tag not available in real Cron Jobs

When you run things on the CLI (which is pretty much where Cronjob and runwhen jobs are running), then you don’t have access to some things like some server or request variable contents, etc. What you need to do is fire up WP Core. Else you won’t have access to the full WP API.

One method would be to use the API from core, but disable WP internal (virtual/fake) Cron system by setting

define( 'DISABLE_WP_CRON', TRUE );

in your wp-config.php file. Then target [~/wp-cron.php] directly – where ~ would be your domain. Keep in mind that you might need to set the proper subdomain or subdirectory when you are running things in a Multisite/Network setup.

WordPress loads the whole core from within this file and then runs every defined (virtual) cron job during the real cron job.

Where it won’t work (opening line inside /wp-cron.php):

// No connection to the browser/client needed
ignore_user_abort( TRUE );

if (
    ! empty( $_POST )
    OR defined( 'DOING_AJAX' )
    OR defined( 'DOING_CRON' )
)
    die();

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)