简体   繁体   English

我想为我的Wordpress网站创建帖子,但是应该将PHP文件放在哪里?

[英]I want to create posts for my Wordpress site, but where should I put the PHP file?

I want to use a PHP file to create posts for my Wordpress site by calling this kind of function: 我想使用一个PHP文件通过调用以下函数为我的Wordpress网站创建帖子:

wp_insert_post( $post, $wp_error );

This PHP file reads some info from a database (not the Wordpress database), perform some data handling, and then call wp_xxxxxx() functions to write data into the Wordpress database. 此PHP文件从数据库(不是Wordpress数据库)读取一些信息,执行一些数据处理,然后调用wp_xxxxxx()函数将数据写入Wordpress数据库。

I was originally thinking to put this PHP in a subdomain, but then I think it should be in somewhere related to the Wordpress because Wordpress functions/database are used. 我本来是想将此PHP放在子域中,但后来我认为它应该放在与Wordpress相关的地方,因为使用了Wordpress函数/数据库。

Where is the best place I should put this file? 我应该在哪里放这个文件? Do I need to include anything in this PHP file? 我需要在此PHP文件中包含任何内容吗? and then I can execute this PHP file via a web browser, like http://xxx.xxx.xxx/yyy1/yyy2/zzz.php ? 然后我可以通过网络浏览器(例如http://xxx.xxx.xxx/yyy1/yyy2/zzz.php)执行此PHP文件?

And this PHP file can be called like a cron job every 15 mins? 而且每15分钟可以将这个PHP文件称为cron作业吗?

I found the solution that best fits my conditions: 我找到了最适合我的条件的解决方案:

Posting in wordpress database as a new post 在WordPress数据库中发布为新帖子

Just like the first answer, I add the PHP in http://MyWordPressdomain.com/scripts and in the PHP header I add 就像第一个答案一样,我将PHP添加到http://MyWordPressdomain.com/scripts中,并在PHP标头中添加

<?php 
    define('WP_USE_THEMES', false);
    require('./wp-blog-header.php');
?>

I can now execute the PHP file from a web browser & from my site's cron job setting directly. 现在,我可以从Web浏览器和网站的cron作业设置中直接执行PHP文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM