## php – Critical Error customiser

Question

Ive successfully added all posts (of a custom post type) to my wordpress menu using this method:Here

Everything is working great. Unfortunately when I view the customiser, I get the “critical error on this website” message, it shows up on the preview pain, the admin navigation is visible however.

This is what I have in my functions file:

/**
*/

function cpt_locations_filter( $items,$menu, $args ) { if ( is_admin() ) { return$items; }
$child_items = array();$menu_order = count($items);$parent_item_id = 0;

foreach ( $items as$item ) {
if ( in_array('history-menu', $item->classes) ){$parent_item_id = $item->ID; } } if($parent_item_id > 0){

foreach ( get_posts( 'post_type=history&numberposts=-1' ) as $post ) {$post->menu_item_parent = $parent_item_id;$post->post_type="nav_menu_item";
$post->object="custom";$post->type="custom";
$post->menu_order = ++$menu_order;
$post->title =$post->post_title;
$post->url = get_permalink($post->ID );
array_push($child_items,$post); // If i comment out this line, the customiser returns as normal.
}

}
return array_merge( $items,$child_items );
}


When I comment out the line containing array_push, the customiser will return as normal. Makes me believe it is something to do with the child_items.

Anyone have any ideas how you would fix this?

Thanks

0
3 weeks 2022-11-11T12:59:41-05:00 0 Answers 0 views 0