* @link http://wp-dreams.com, http://codecanyon.net/user/anago/portfolio * @copyright Copyright (c) 2016, Ernest Marcinko */ class wd_CPTSelect extends wpdreamsType { private $args = array( 'show_parent_checkbox' => 1 ); private $e_data; public function getType() { parent::getType(); $this->processData(); ?>
label; ?>

    :)

e_data['op_type']; ?>!

    printSelectedPosts(); ?>
e_data['ids']) > 0 ) { $ptypes = get_post_types(array( "public" => true, "_builtin" => false ), "names", "OR"); $ptypes = array_diff($ptypes, array( "revision", "nav_menu_item", "attachment", "acf", "wpcf7_contact_form", "dslc_templates", "acf-field", "acf-group", "acf-groups" )); $items = get_posts(array( 'posts_per_page' => count($this->e_data['ids']), 'post_type' => $ptypes, 'post__in' => $this->e_data['ids'], 'post_status' => 'any' )); foreach ($items as $p) { if (empty($p) || is_wp_error($p)) continue; $checkbox = ""; if ($this->args['show_parent_checkbox'] == 1 && $p->post_type == 'page') $checkbox = '
' . __('Exclude direct children too?', 'ajax-search-pro') . ' ID, $this->e_data['parent_ids']) ? ' checked="checked"' : '') . '/>
'; echo '
  • ' . $p->post_title . ' [id: '.$p->ID.'] [' . $p->post_type . '] [' . $p->post_status . '] ' . $checkbox . '
  • '; } } } public static function searchPosts() { if ( isset($_POST['wd_phrase'], $_POST['wd_cpt_select_search_nonce']) && ( current_user_can( 'manage_options' ) || apply_filters('wpdrms/backend/options/ajax/user_role_override', false) ) && wp_verify_nonce( $_POST["wd_cpt_select_search_nonce"], 'wd_cpt_select_search_nonce' ) ) { $phrase = trim($_POST['wd_phrase']); $data = json_decode(base64_decode($_POST['wd_args']), true); $ptypes = get_post_types(array( "public" => true, "_builtin" => false ), "names", "OR"); $exclude = array("revision", "nav_menu_item", 'peepso-post', 'peepso-comment', "acf", "oembed_cache", "user_request", "wp_block", "shop_coupon", "avada_page_options", "_pods_template", "_pods_pod", "_pods_field", "bp-email", "lbmn_archive", "lbmn_footer", "mc4wp-form", "elementor-front", "elementor-icon", "fusion_template", "fusion_element", "wc_product_tab", "customize_changeset", "wpcf7_contact_form", "dslc_templates", "acf-field", "acf-group", "acf-groups", "acf-field-group", "custom_css"); $ptypes = array_diff($ptypes, $exclude); $asp_query = new SearchQuery(array( "s" => $phrase, "_ajax_search" => false, 'keyword_logic' => 'and', 'secondary_logic' => 'or', "posts_per_page" => 20, 'post_type' => $ptypes, 'post_status' => array('publish', 'future', 'pending', 'private'), 'post_fields' => array( 'title', 'ids' ) )); $results = $asp_query->posts; Ajax::prepareHeaders(); if ( ! empty( $results ) ) { echo "Results (".count($results)."): "; foreach ( $results as $p ) { $checkbox = ""; if ($data['show_parent_checkbox'] == 1 && $p->post_type == 'page') $checkbox = '
    ' . __('Exclude direct children too?', 'ajax-search-pro') . '
    '; echo '
  • '. $p->post_title . ' [id: '.$p->ID.'] ['.$p->post_type.'] ['.$p->post_status.'] ' . $checkbox . '
  • '; } } else { echo __('No items found for term:', 'ajax-search-pro') . ' ' . esc_html($phrase) .''; } } die(); } public function processData() { // Get the args first if exists if ( is_array($this->data) && isset($this->data['args']) ) $this->args = array_merge($this->args, $this->data['args']); if ( is_array($this->data) && isset($this->data['value']) ) { // If called from back-end non-post context $this->e_data = $this->decode_param($this->data['value']); $this->data = $this->encode_param($this->data['value']); } else { // POST method or something else $this->e_data = $this->decode_param($this->data); $this->data = $this->encode_param($this->data); } /** * At this point the this->data variable surely contains the encoded data, no matter what. */ } public final function getData() { return $this->data; } public final function getSelected() { return $this->e_data; } } } if ( !has_action('wp_ajax_wd_search_cpt') ) add_action('wp_ajax_wd_search_cpt', 'wd_CPTSelect::searchPosts');