get_results( $wpdb->prepare( "SELECT ID, post_title FROM $wpdb->posts WHERE $wpdb->posts.post_type = %s AND $wpdb->posts.post_status = %s ORDER BY ID DESC", $cpt_type, $cpt_post_status ) ); $list = array(); foreach ( $cpt as $post ) { $selected = ''; $post_id = $post->ID; $post_name = $post->post_title; $list[] = array( 'text' => $post_name, 'value' => $post_id, ); } wp_send_json( $list ); } /** * Function to fetch buttons * * @since 2.0 * @return string */ public function pc_list_ajax() { // check for nonce check_ajax_referer( 'sp-mce-nonce', 'security' ); $posts = $this->posts( 'sp_pc_shortcodes' ); // change 'post' if you need posts list return $posts; } /** * Function to output button list ajax script * * @since 2.0 * @return string */ public function pc_cpt_list() { // create nonce global $current_screen; $current_screen->post_type; if ( $current_screen == 'post' || 'page' ) { $nonce = wp_create_nonce( 'sp-mce-nonce' ); ?> init();