我为wordpress网站开发了一个主题和一些插件。 插件全部用于自定义帖子类型。我试着寻找解决方案几个小时,但我找到的所有解决方案似乎都不适合我。许多解决方案表明需要调用一个数组才能使foreach参数起作用,但我相当确定我的插件已经准确地使用了一个数组。我在我的本地dev上创建了一个完全正常工作的站点,没有任何错误,但是当我在我的网站的live子目录中安装任何插件时(为了演示),我得到以下三个错误:
" 在第1468行的/home3/adamshap/public_html/usdbls/wp-includes/post.php中为foreach()提供的参数无效"
" 无法修改标题信息 - 已在/ home3 / adamshap中发送的标题(输出从/home3/adamshap/public_html/usdbls/wp-includes/post.php:1468开始)第787行/public_html/usdbls/wp-includes/option.php "
" 无法修改标题信息 - 已在/ home3 / adamshap中发送的标题(输出从/home3/adamshap/public_html/usdbls/wp-includes/post.php:1468开始)第788行/public_html/usdbls/wp-includes/option.php "
其他信息: 我只在上传自定义post_type插件时收到错误(不是我开发的主题,只是插件)。 错误出现在我的所有插件上,而不是任何一个插件。 我知道错误在于我制作的插件,所以我需要找出如何修复我的插件,而不是wordpress核心文件。
第一个错误指向wp-includes / post.php的第1468行。 相应的代码部分如下:
if ( $args->register_meta_box_cb )
add_action( 'add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1 );
$args->labels = get_post_type_labels( $args );
$args->label = $args->labels->name;
$wp_post_types[ $post_type ] = $args;
add_action( 'future_' . $post_type, '_future_post_hook', 5, 2 );
foreach ( $args->taxonomies as $taxonomy ) {
register_taxonomy_for_object_type( $taxonomy, $post_type );
}
第二个和第三个错误指向wp-includes / option.php文件中的这段代码:
// The cookie is not set in the current browser or the saved value is newer.
$secure = ( 'https' === parse_url( site_url(), PHP_URL_SCHEME ) );
setcookie( 'wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure );
setcookie( 'wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure );
$_COOKIE['wp-settings-' . $user_id] = $settings;
看到这两个文件都是wordpress核心文件,我相信错误实际上是在我的插件代码中,而不是上面的代码段。下面的Dropbox链接链接到我完成的一个插件的txt文件(它超过了stackoverflow的字符限制)。
https://www.dropbox.com/s/137djd6x13wp2e5/about-intro.txt?dl=0
提前感谢您的帮助!
答案 0 :(得分:2)
解决方案发现,部分归功于用户Marc B的上述评论。
我们发现在三个错误中,真正的错误只是第一个错误,第一个错误产生了额外的两个错误。
我的第一个解决方案是从以下位置更改wp-includes / post.php文件(第1468行 - 第1470行):
foreach ( $args->taxonomies as $taxonomy ) {
register_taxonomy_for_object_type( $taxonomy, $post_type );
}
到此:
if (is_array($taxonomy) || is_object($taxonomy)) {
foreach ($args ->taxonomies as $taxonomy) {
register_taxonomy_for_object_type($taxonomy, $post_type);
}
}
虽然这解决了我的问题,但这是一个糟糕的解决方案,因为它需要编辑wp核心文件。在Marc B建议使用var_dump并找到使用分类数组的插件部分(错误地)之后,我找到了真正的解决方案:
我的插件使用以下原始代码注册了自定义post_type:
$args = array(
'label' => __( 'Statement', 'text_domain' ),
'description' => __( 'About Statement', 'text_domain' ),
'labels' => $labels,
'supports' => array('',''),
'taxonomies' => false,
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => true,
'publicly_queryable' => true,
'query_var' => 'about',
'capability_type' => 'page',
);
register_post_type( 'about_type', $args );
}
add_action( 'init', 'about_post_type', 0);
如您所见,$ args数组将“分类法”定义为“false”。这是造成错误的原因。解决方案是简单地将值'false'更改为数组。固定功能如下:
$args = array(
'label' => __( 'Statement', 'text_domain' ),
'description' => __( 'About Statement', 'text_domain' ),
'labels' => $labels,
'supports' => array('',''),
'taxonomies' => array(),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => true,
'publicly_queryable' => true,
'query_var' => 'about',
'capability_type' => 'page',
);
在自己寻找答案时,我发现很多人似乎都有这个问题。如果您正在寻找类似的解决方案,我建议您查看插件的register_post_type函数,以了解该数组如何处理分类法。