I have this error coming up on my wp_debug log file: [09-Aug-2016 11:05:05 UTC] PHP Warning: Invalid argument supplied for foreach() in ...wp-content/themes/mytheme/custom-post-types/cpts.php on line 23
I cannot seem to see why this would give that that error...
The code in question is as follows
$cpts = array(
array('shows','Show','Shows','dashicons-tickets-alt',array('title','editor','thumbnail','comments')),
array('people','Person','Team','dashicons-groups',array('title','editor','thumbnail')),
array('cast','Cast & Crew','Cast & Crew','dashicons-universal-access',array('title','editor','thumbnail')),
array('brochures','Brochure','Brochures','dashicons-book',array('title','editor','thumbnail')),
array('jobs','Job','Jobs','dashicons-businessman',array('title','editor','thumbnail')),
array('businesses','Business','Businesses','dashicons-building',array('title','editor','thumbnail')),
array('prices','Price List','Price Lists','dashicons-money', array('title')),
);
function cpts_register() {
global $cpts;
foreach($cpts as $cpt){
$cpt_wp_name = $cpt[0];
$cpt_singular = $cpt[1];
$cpt_plural = $cpt[2];
$cpt_image = $cpt[3];
$cpt_suports = $cpt[4];
$labels = array(
'name' => _x($cpt_plural, 'post type general name'),
'singular_name' => _x($cpt_singular, 'post type singular name'),
'add_new' => _x('Add New', $cpt_wp_name),
'add_new_item' => __('Add New '.$cpt_singular),
'edit_item' => __('Edit '.$cpt_singular),
'new_item' => __('New '.$cpt_singular),
'view_item' => __('View '.$cpt_singular),
'search_items' => __('Search '.$cpt_plural),
'not_found' => __('No '.$cpt_plural.' Found'),
'not_found_in_trash' => __('No '.$cpt_plural.' Found in Trash'),
'parent_item_colon' => '',
);
$args = array(
'labels' => $labels,
'public' => true,
'show_ui' => true,
'publicly_queryable' => true,
'query_var' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => true,
'show_in_rest' => true,
'supports' => $cpt_suports,
'menu_icon' => $cpt_image,
);
register_post_type($cpt_wp_name, $args );
}
}
Thanks in advance for your help...
M