I am building an Admin page for my themes. In the admin page, it will be possible for admins to go to the options page and select how many custom post types they want to open. I've already got the first part running (the page where they put in how many custom post types they want, and what the names of those custom post types should be). I am having trouble with the second part: using a foreach loop to get information that has been collected in the first step and putting it through a function to register that post type.
Start of the foreach-loop:
foreach($custom_post_type_select as $custom_post_type) {
$custom_post_type_number = $custom_post_type_integer+1;
$custom_post_type_name = "custom_post_type_name_$custom_post_type_number";
$register_custom_post_type_name = $custom_post_type_selection[$custom_post_type_name];
$custom_post_type_marker = "custom_post_type_activate_$custom_post_type_number";
$register_custom_post_type_activate = $custom_post_type_selection[$custom_post_type_marker];
Registering the custom post type:
function register_custom_post_type() {
$args = array(
'public' => true,
'labels' => array(
'name' => $register_custom_post_type_name,
'singular_name' => $register_custom_post_type_name,
'public' => true,
'has_archive' => true,
'supports' => array('title'),
'show_ui' => true);
register_post_type($register_custom_post_type_name,$args);};
if(stripos($register_custom_post_type_activate,'yes') !== false) {
add_action('init','register_custom_post_type');}
And the end of the foreach-loop:
if(++$custom_post_type_integer == $custom_post_type_variable)
break;}}
How would it be possible to both use the foreach-loop to get the right information and a function that is being called by an add_action?