Running CRON on Server with WP Function

How can I run a WP function on server cron?Background: I can't run it on wp_cron because the website is not publish

How can I run a WP function on server cron?

Background: I can't run it on wp_cron because the website is not published and will not be, so there will be no visitors. Tested cron job without wp function, it is working properly (like sending email every 30 minutes).

//RemoteCoins() and LoadRemoteCoins() that include wp functions like wp_remote_get()

function runthe_func() {

//some code here

}

runthe_func();

I kept on getting errors like: "Fatal error: Call to undefined function wp_remote_get() in /home/path/path2/testing.php on line 91"

How can I make it run with the server recognizing wp functions?

How can I run a WP function on server cron?

Background: I can't run it on wp_cron because the website is not published and will not be, so there will be no visitors. Tested cron job without wp function, it is working properly (like sending email every 30 minutes).

//RemoteCoins() and LoadRemoteCoins() that include wp functions like wp_remote_get()

function runthe_func() {

//some code here

}

runthe_func();

I kept on getting errors like: "Fatal error: Call to undefined function wp_remote_get() in /home/path/path2/testing.php on line 91"

How can I make it run with the server recognizing wp functions?

Share Improve this question asked May 17, 2019 at 2:25 kriskrosskriskross 131 silver badge3 bronze badges 3
  • Welcome to WPSE. Short answer: You need to include wp-load.php in order to let your custom function recognize WP functions. – Pothi Kalimuthu Commented May 17, 2019 at 3:54
  • 1 @PothiKalimuthu, thank you. It was the answer to my question. – kriskross Commented May 17, 2019 at 6:30
  • That's nice to know. Just put my short answer as a real answer to this question. – Pothi Kalimuthu Commented May 17, 2019 at 9:02
Add a comment  | 

2 Answers 2

Reset to default 1

We need to include wp-load.php in order to bootstrap WordPress in our custom PHP code. So, the modified code would look something like this...

include '/path/to/wp-load.php';
//RemoteCoins() and LoadRemoteCoins() that include wp functions like wp_remote_get()

function runthe_func() {

//some code here

}

runthe_func();

Now, if we run this file on server cron, it wouldn't throw errors.

Oh, btw, similar questions have been asked and answered multiple times here in WPSE. For example, How to load WordPress on non WP page? .

@kriskross Welcome to the Community.

First of all, you need to create a scheduled event for WordPress cron jobs. You need to stay in functions.php (placed on your themes) or related files (plugin files etc.) for calling WordPress core functions. Also, you can create cron jobs from server side.

if you want to schedule please read and follow these instructions.

Create Server Handled Cron Jobs

place this configuration in your wp-config.php file before That's all, stop editing! Happy blogging.

define('DISABLE_WP_CRON', true);

after that, You need to create cron jobs from you local server (You said my website will not be released or get any visitors).

Here is the web based cron trigger link.

wget -q -O - http://yourdomain/wp-cron.php?doing_wp_cron >/dev/null 2>&1

You can use online crontab generator like websites for timing and crontab.

I hope this will be your solution.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745485089a4629729.html

相关推荐

  • Running CRON on Server with WP Function

    How can I run a WP function on server cron?Background: I can't run it on wp_cron because the website is not publish

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信