コード例 #1
0
ファイル: Ajax_Helper.php プロジェクト: rebeccayshen/kitlist
    public static function wpcf_search_posts_for_groups_ajax()
    {
        if (!current_user_can('manage_options')) {
            _e('There are security problems. You do not have permissions.', 'wpcf-access');
            die;
        }
        if (!isset($_POST['wpnonce']) || !wp_verify_nonce($_POST['wpnonce'], 'wpcf-access-error-pages')) {
            die('verification failed');
        }
        $out = '';
        $post_types_array = array();
        $post_types = get_post_types(array('public' => true), 'names');
        foreach ($post_types as $post_type) {
            $post_types_array[] = $post_type;
        }
        $args = array('posts_per_page' => '10', 'post_status' => 'publish', 'post_type' => $post_types_array, 's' => Access_Helper::wpcf_esc_like($_POST['title']));
        $the_query = new WP_Query($args);
        if ($the_query->have_posts()) {
            while ($the_query->have_posts()) {
                $the_query->the_post();
                $out .= '
					<li>' . get_the_title() . ' <a href="" class="js-wpcf-add-post-to-group"
						data-title="' . esc_js(get_the_title()) . '"
						data-id="' . esc_attr(get_the_ID()) . '">+ ' . __('Add', 'wpcf-access') . '</a>
					</li>';
            }
        }
        print $out;
        die;
    }