在wordpress根目录之外的webservice中使用WordPress功能

时间:2017-07-17 19:28:03

标签: php wordpress web-services

我在服务器上的Web服务目录中调用vanilla Wordpress函数时遇到了一些问题。

我有这样的结构:

Root

- webservice
- - service.php
- wordpress
- - wordpress-root

我从谷歌这个问题开始,找到一些像这样的解决方案......

require($_SERVER['DOCUMENT_ROOT'].'/wordpress-root/wp-load.php');

require($_SERVER['DOCUMENT_ROOT'].'/wordpress-root/wp-blog-header.php');

我将这些行添加到service.php中。 现在我的浏览器开始将我重定向到以下URL并抛出错误  wp-admin/install.php

 The requested URL /wp-admin/install.php was not found on this server.

有人有解决这个问题的可靠方法吗?

//修改

调试后发现重定向是在function.php

中的这行代码之后抛出的
    /*
 * Loop over the WP tables. If none exist, then scratch install is allowed.
 * If one or more exist, suggest table repair since we got here because the
 * options table could not be accessed.
 */
$wp_tables = $wpdb->tables();
foreach ( $wp_tables as $table ) {
    // The existence of custom user tables shouldn't suggest an insane state or prevent a clean install.
    if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE == $table )
        continue;
    if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE == $table )
        continue;
    // Error throw after this lines
    if ( ! $wpdb->get_results( "DESCRIBE $table;" ) )
        continue;

2 个答案:

答案 0 :(得分:0)

当wordpress认为这是一个新安装时,

重定向到install.php。当wordpress无法在数据库中找到特定条目时,就会发生这种情况。 (option_name =='siteurl'的选项表)

打开文件functions.php并搜索函数is_blog_installed。然后调试为什么这个函数认为没有安装wordpress。

我的猜测是无法读取配置文件或某些变量为空。还要检查文件权限是否正确。

您也可以尝试通过脚本设置变量。另请参阅site_url函数。

答案 1 :(得分:0)

define('WP_USE_THEMES', false);
require($_SERVER['DOCUMENT_ROOT'].'/wp-blog-header.php')

define('WP_USE_THEMES', false);
require($_SERVER['DOCUMENT_ROOT'].'/wp-load.php')

https://wordpress.stackexchange.com/q/47049/10911