// add_action('add_meta_boxes', array($this, 'answer_meta_action'));
add_action('admin_menu', array($this, 'answer_meta_action'));
public function answer_meta_action() {
add_meta_box(
'ttl-to-edit',
__('Edit In Response To', 'ttl-p'),
array($this, 'response_to_edit'),
'ttl', // Custom Post Type
'normal',
'high'
);
}
public function response_to_edit()
{
$post_types = get_post_types();
?>
<style>.clearfix {overflow: auto;}.clearfix::after {content: "";clear: both;display: table;}</style>
<span class="tsqa_response_to_action-error" style="color:#ff0000;"></span>
<div id="tsqa_response_to_action">
<div style="margin: 10px 0 10px 0;" class="clearfix">
<div class="box-section" style="width:250px;float:left;">
<strong><label>Post Type:</label></strong> <br>
<select name="post_type" style="width: 200px;margin-right:20px;">
<option value="">- Select -</option>
<?php foreach( $post_types as $post_type ): ?>
<option value="<?php echo $post_type ?>"><?php echo $post_type ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
<?php
}
CPT Register:
add_action('init', array($this, 'init'));
public function init() {
$labels = array(
'name' => _x( 'Question', 'Post Type General Name', '' ),
....
);
$args = array(
'labels' => $labels,
'description' => __( 'Questions', '' ),
'public' => false,
'publicly_queryable' => false,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-format-status',
'query_var' => true,
'rewrite' => array('slug'=>'question'),
'capability_type' => 'post',
'capabilities' => array(
'create_posts' => 'do_not_allow',
),
'map_meta_cap' => true,
'has_archive' => 'questions',
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor' ),
);
register_post_type( 'ttl', $args );
flush_rewrite_rules();
}