我使用CCTM plugin 和复制/粘贴存档。php存档车辆。php,但这导致我的标题中出现错误:
Warning: in_array() expects parameter 2 to be array, null given in /home/.../public_html/wp-includes/nav-menu-template.php on line 439
每个主菜单项(没有子菜单)都会重复相同的错误。
如果我移除存档车辆。php和使用归档查看相同的帖子。php没有出现错误。
为什么会这样?
Update
导航菜单模板第439行。php是
in_array( $parent_item->object_id, $queried_object->ancestors )
print_r($queried_object)
就在第439行生成以下内容之前-没有“祖先”键:
stdClass Object ( [labels] => stdClass Object ( [name] => Vehicles [singular_name] => Vehicle [add_new] => Add New [add_new_item] => Add New Vehicle [edit_item] => Edit Vehicle [new_item] => New Vehicle [view_item] => View Vehicle [search_items] => Search Vehicles [not_found] => No Vehicles Found [not_found_in_trash] => No Vehicles found in Trash [parent_item_colon] => Operator [all_items] => Vehicles [menu_name] => Vehicles [name_admin_bar] => Vehicle ) [description] => Each vehicle is linked to an Operator [publicly_queryable] => 1 [exclude_from_search] => [capability_type] => post [map_meta_cap] => 1 [_builtin] => [_edit_link] => post.php?post=%d [hierarchical] => 1 [public] => 1 [rewrite] => Array ( [slug] => vehicle [with_front] => 1 [pages] => 1 [feeds] => 1 [ep_mask] => 1 ) [has_archive] => 1 [query_var] => [register_meta_box_cb] => [taxonomies] => Array ( [0] => category [1] => features [2] => colours [3] => drivers ) [show_ui] => 1 [menu_position] => [menu_icon] => [can_export] => 1 [show_in_nav_menus] => 1 [show_in_menu] => 1 [show_in_admin_bar] => 1 [delete_with_user] => [cctm_hierarchical_custom] => 1 [cctm_hierarchical_includes_drafts] => [cctm_hierarchical_post_types] => Array ( [0] => operator ) [cctm_custom_columns_enabled] => 0 [post_type] => vehicle [use_default_menu_icon] => 1 [label] => Vehicles [cctm_show_in_menu] => 1 [cctm_show_in_menu_custom] => [rewrite_with_front] => 1 [permalink_action] => /%postname%/ [rewrite_slug] => [include_in_search] => 1 [include_in_rss] => 1 [cctm_enable_right_now] => 1 [custom_order] => ASC [is_active] => 1 [custom_fields] => Array ( [0] => passenger_capacity [1] => luggage_capacity [2] => hourly_rate [3] => included_milleage [4] => additional_mileage_price [5] => additional_image ) [map_field_metabox] => Array ( [passenger_capacity] => cctm_vehicledetails [luggage_capacity] => cctm_vehicledetails [hourly_rate] => cctm_vehicledetails [included_milleage] => cctm_vehicledetails [additional_mileage_price] => cctm_vehicledetails [additional_image] => cctm_default ) [original_post_type_name] => vehicle [name] => vehicle [cap] => stdClass Object ( [edit_post] => edit_post [read_post] => read_post [delete_post] => delete_post [edit_posts] => edit_posts [edit_others_posts] => edit_others_posts [publish_posts] => publish_posts [read_private_posts] => read_private_posts [read] => read [delete_posts] => delete_posts [delete_private_posts] => delete_private_posts [delete_published_posts] => delete_published_posts [delete_others_posts] => delete_others_posts [edit_private_posts] => edit_private_posts [edit_published_posts] => edit_published_posts [create_posts] => edit_posts ) ) stdClass Object ( [labels] => stdClass Object ( [name] => Vehicles [singular_name] => Vehicle [add_new] => Add New [add_new_item] => Add New Vehicle [edit_item] => Edit Vehicle [new_item] => New Vehicle [view_item] => View Vehicle [search_items] => Search Vehicles [not_found] => No Vehicles Found [not_found_in_trash] => No Vehicles found in Trash [parent_item_colon] => Operator [all_items] => Vehicles [menu_name] => Vehicles [name_admin_bar] => Vehicle ) [description] => Each vehicle is linked to an Operator [publicly_queryable] => 1 [exclude_from_search] => [capability_type] => post [map_meta_cap] => 1 [_builtin] => [_edit_link] => post.php?post=%d [hierarchical] => 1 [public] => 1 [rewrite] => Array ( [slug] => vehicle [with_front] => 1 [pages] => 1 [feeds] => 1 [ep_mask] => 1 ) [has_archive] => 1 [query_var] => [register_meta_box_cb] => [taxonomies] => Array ( [0] => category [1] => features [2] => colours [3] => drivers ) [show_ui] => 1 [menu_position] => [menu_icon] => [can_export] => 1 [show_in_nav_menus] => 1 [show_in_menu] => 1 [show_in_admin_bar] => 1 [delete_with_user] => [cctm_hierarchical_custom] => 1 [cctm_hierarchical_includes_drafts] => [cctm_hierarchical_post_types] => Array ( [0] => operator ) [cctm_custom_columns_enabled] => 0 [post_type] => vehicle [use_default_menu_icon] => 1 [label] => Vehicles [cctm_show_in_menu] => 1 [cctm_show_in_menu_custom] => [rewrite_with_front] => 1 [permalink_action] => /%postname%/ [rewrite_slug] => [include_in_search] => 1 [include_in_rss] => 1 [cctm_enable_right_now] => 1 [custom_order] => ASC [is_active] => 1 [custom_fields] => Array ( [0] => passenger_capacity [1] => luggage_capacity [2] => hourly_rate [3] => included_milleage [4] => additional_mileage_price [5] => additional_image ) [map_field_metabox] => Array ( [passenger_capacity] => cctm_vehicledetails [luggage_capacity] => cctm_vehicledetails [hourly_rate] => cctm_vehicledetails [included_milleage] => cctm_vehicledetails [additional_mileage_price] => cctm_vehicledetails [additional_image] => cctm_default ) [original_post_type_name] => vehicle [name] => vehicle [cap] => stdClass Object ( [edit_post] => edit_post [read_post] => read_post [delete_post] => delete_post [edit_posts] => edit_posts [edit_others_posts] => edit_others_posts [publish_posts] => publish_posts [read_private_posts] => read_private_posts [read] => read [delete_posts] => delete_posts [delete_private_posts] => delete_private_posts [delete_published_posts] => delete_published_posts [delete_others_posts] => delete_others_posts [edit_private_posts] => edit_private_posts [edit_published_posts] => edit_published_posts [create_posts] => edit_posts ) )
Update 2
存档车辆。php:
<?php
/**
* The template for displaying Archive pages.
*
* Used to display archive-type pages if nothing more specific matches a query.
* For example, puts together date-based pages if no date.php file exists.
*
* Learn more: http://codex.wordpress.org/Template_Hierarchy
*
* @package WordPress
* @subpackage Twenty_Ten
* @since Twenty Ten 1.0
*/
get_header(); ?>
<div class="container">
<div class="row">
<div class="col-md-8">
<div id="content" role="main">
<?php
/* Queue the first post, that way we know
* what date we\'re dealing with (if that is the case).
*
* We reset this later so we can run the loop
* properly with a call to rewind_posts().
*/
if ( have_posts() )
the_post();
?>
<h1 class="page-title">
<?php if ( is_day() ) : ?>
<?php printf( __( \'Daily Archives: <span>%s</span>\', \'twentyten\' ), get_the_date() ); ?>
<?php elseif ( is_month() ) : ?>
<?php printf( __( \'Monthly Archives: <span>%s</span>\', \'twentyten\' ), get_the_date( _x( \'F Y\', \'monthly archives date format\', \'twentyten\' ) ) ); ?>
<?php elseif ( is_year() ) : ?>
<?php printf( __( \'Yearly Archives: <span>%s</span>\', \'twentyten\' ), get_the_date( _x( \'Y\', \'yearly archives date format\', \'twentyten\' ) ) ); ?>
<?php else : ?>
<?php _e( \'Blog Archives\', \'twentyten\' ); ?>
<?php endif; ?>
</h1>
<?php
/* Since we called the_post() above, we need to
* rewind the loop back to the beginning that way
* we can run the loop properly, in full.
*/
rewind_posts();
/* Run the loop for the archives page to output the posts.
* If you want to overload this in a child theme then include a file
* called loop-archive.php and that will be used instead.
*/
get_template_part( \'loop\', \'archive\' );
?>
</div><!-- #content -->
</div><!-- .col-md-8 -->
<div class="col-md-3 col-md-offset-1">
<?php get_sidebar(); ?>
</div><!-- .col-md-3 -->
</div><!-- .row -->
</div><!-- .container -->
<?php get_footer(); ?>
Update 3
wp内容\\插件\\自定义内容类型管理器\\控制器\\创建\\u post\\u类型。php:
<?php
/*------------------------------------------------------------------------------
Create a new post type.
------------------------------------------------------------------------------*/
if ( ! defined(\'CCTM_PATH\')) exit(\'No direct script access allowed\');
if (!current_user_can(\'administrator\')) exit(\'Admins only.\');
require_once(CCTM_PATH.\'/includes/CCTM_PostTypeDef.php\');
$data=array();
$data[\'page_title\'] = __(\'Create Custom Content Type\', CCTM_TXTDOMAIN);
$data[\'help\'] = \'http://code.google.com/p/wordpress-custom-content-type-manager/wiki/CreatePostType\';
$data[\'msg\'] = \'\';
$data[\'menu\'] = sprintf(\'<a href="\'.get_admin_url(false,\'admin.php\').\'?page=cctm" title="%s" class="button">%s</a>\', __(\'Cancel\'), __(\'Cancel\'));
$data[\'edit_warning\'] = \'\'; // only used when you edit a post_type, not delete.
// Variables for our template
$fields = \'\';
$data[\'action_name\'] = \'custom_content_type_mgr_create_new_content_type\';
$data[\'nonce_name\'] = \'custom_content_type_mgr_create_new_content_type_nonce\';
$data[\'submit\'] = __(\'Create New Content Type\', CCTM_TXTDOMAIN);
$data[\'action\'] = \'create\';
$data[\'post_type\'] = \'\'; // as default
$data[\'def\'] = self::$default_post_type_def;
// $def = self::$post_type_form_definition;
// Save data if it was properly submitted
if ( !empty($_POST) && check_admin_referer($data[\'action_name\'], $data[\'nonce_name\']) ) {
$sanitized_vals = CCTM_PostTypeDef::sanitize_post_type_def($_POST);
$error_msg = CCTM_PostTypeDef::post_type_name_has_errors($sanitized_vals, true);
if ( empty($error_msg) ) {
// Clean slate. This nukes any instance of \'is_foreign\' (and potentially other issues)
// that may arise if the post-type name was used by another plugin and the CCTM tracked
// custom fields for that plugin, and then later the other plugin was deactivated and
// the CCTM wants to use the same post-type name.
unset(CCTM::$data[\'post_type_defs\'][ $sanitized_vals[\'post_type\'] ]);
CCTM_PostTypeDef::save_post_type_settings($sanitized_vals);
$data[\'msg\'] = CCTM::format_msg( sprintf(__(\'The content type %s has been created\', CCTM_TXTDOMAIN), \'<em>\'.$sanitized_vals[\'post_type\'].\'</em>\'));
self::set_flash($data[\'msg\']);
include CCTM_PATH . \'/controllers/list_post_types.php\';
return;
}
else {
// clean up... menu labels in particular can get gunked up. :(
$data[\'def\'] = $sanitized_vals;
$data[\'def\'][\'labels\'][\'singular_name\'] = \'\';
$data[\'def\'][\'label\'] = \'\';
$data[\'msg\'] = CCTM::format_error_msg($error_msg);
}
}
$data[\'icons\'] = CCTM_PostTypeDef::get_post_type_icons();
$data[\'columns\'] = CCTM_PostTypeDef::get_columns($post_type);
$data[\'orderby_options\'] = CCTM_PostTypeDef::get_orderby_options($post_type);
$data[\'content\'] = CCTM::load_view(\'post_type.php\', $data);
print CCTM::load_view(\'templates/default.php\', $data);
/*EOF*/
wp content\\plugins\\custom content type manager\\includes\\CCTM。php register\\u custom\\u post\\u types函数:
public static function register_custom_post_types() {
//return;
$post_type_defs = self::get_post_type_defs();
foreach ($post_type_defs as $post_type => $def) {
$def = self::_prepare_post_type_def($def);
if ( isset($def[\'is_active\'])
&& !empty($def[\'is_active\'])
&& !in_array($post_type, self::$built_in_post_types)
&& isset($def[\'post_type\'])
) {
register_post_type( $post_type, $def );
}
}
// Added per issue 50
// http://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=50
if (self::get_setting(\'flush_permalink_rules\')){
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
}
最合适的回答,由SO网友:chrisguitarguy 整理而成
在第439行生成以下内容之前打印\\r($queryed\\u object)-没有“祖先”键:
当您进行post类型存档调用时get_queried_object
(代码可能会这样做)或使用WP_Query::$queried_object
返回post类型“object”。所有这些都是post类型注册时使用的参数。
的相关位nav-menu-template.php
在WordPress 3.6中。
<?php
function _wp_menu_item_classes_by_context( &$menu_items ) {
// ...
foreach ( (array) $menu_items as $key => $parent_item ) {
// ...
if (
isset( $parent_item->type ) &&
(
// ancestral post object
(
\'post_type\' == $parent_item->type &&
! empty( $queried_object->post_type ) &&
is_post_type_hierarchical( $queried_object->post_type ) &&
in_array( $parent_item->object_id, $queried_object->ancestors ) &&
$parent_item->object != $queried_object->ID
) ||
// ancestral term
(
\'taxonomy\' == $parent_item->type &&
isset( $possible_taxonomy_ancestors[ $parent_item->object ] ) &&
in_array( $parent_item->object_id, $possible_taxonomy_ancestors[ $parent_item->object ] ) &&
(
! isset( $queried_object->term_id ) ||
$parent_item->object_id != $queried_object->term_id
)
)
)
) {
$classes[] = empty( $queried_object->taxonomy ) ? \'current-\' . $queried_object->post_type . \'-ancestor\' : \'current-\' . $queried_object->taxonomy . \'-ancestor\';
}
// ...
}
// ...
}
这个钻头
! empty( $queried_object->post_type )
应在柱式档案上评估为假。正在向查询的对象添加post类型。通过某种方式
I mean your plugin 这是
_doing_it_wrong
. 看看
CCTM::register_custom_post_types()
和
CCTM::$default_post_type_def
.
任何被传递到register_post_type
只是作为参数存储在post类型的全局数组中。
如果我这样做:
register_post_type(\'some_type\', array(\'this_is_not_a_wp_arg\' => true));
在上
archive-some_type.php
我可以查一下
this_is_not_a_wp_arg
.
<?php
// archive-some_type.php
var_dump(get_queried_object()->this_is_not_a_wp_arg); // true
因为你的插件碰巧
post_type
在arguments数组中,它会使WP求值
! empty( $queried_object->post_type )
这是真的。这不是
archive.php
因为
$query_object->post_type
为空。因为它应该在任何post类型的存档上。不幸的是,CCTM插件作者不理解传递“保留”字的后果,如
post_type
作为论点的关键。这就是为什么在事物前面加前缀很重要。
EDIT
一个非常老套的解决方法是
init
非常晚,并循环浏览所有帖子类型。如果
post_type
参数已设置,请将其删除。这可能会破坏插件在管理区域的其他功能。
<?php
add_action(\'init\', \'wpse115604_fix\', 10000);
function wpse115604_fix()
{
foreach (get_post_types(array(), \'objects\') as $type) {
if (isset($type->post_type)) {
unset($type->post_type);
}
}
}
这将避免您必须编辑插件本身。我会这样做,然后将问题报告给插件作者。如果/当它在将来的版本中得到修复,您将能够删除该代码。
TL;DR: CCTM向名为post_type
它扰乱了事物的秩序,并在运动中设置了一系列错误。