function siteorigin_widget_post_selector_process_query($query)
{
    $query = wp_parse_args($query, array('post_status' => 'publish', 'posts_per_page' => 100));
    if (!empty($query['post_type'])) {
        if ($query['post_type'] == '_all') {
            $query['post_type'] = siteorigin_widget_post_selector_all_post_types();
        }
        $query['post_type'] = explode(',', $query['post_type']);
    }
    if (!empty($query['post__in'])) {
        $query['post__in'] = explode(',', $query['post__in']);
        array_map('intval', $query['post__in']);
    }
    if (!empty($query['tax_query'])) {
        $tax_queries = explode(',', $query['tax_query']);
        $query['tax_query'] = array();
        foreach ($tax_queries as $tq) {
            list($tax, $term) = explode(':', $tq);
            if (empty($tax) || empty($term)) {
                continue;
            }
            $query['tax_query'][] = array('taxonomy' => $tax, 'field' => 'slug', 'terms' => $term);
        }
    }
    return $query;
}
/**
 * The action handler for searching posts by title
 */
function siteorigin_widget_post_selector_post_search_action()
{
    if (empty($_REQUEST['_widgets_nonce']) || !wp_verify_nonce($_REQUEST['_widgets_nonce'], 'widgets_action')) {
        return;
    }
    $term = !empty($_GET['term']) ? stripslashes($_GET['term']) : '';
    $type = !empty($_GET['type']) ? stripslashes($_GET['type']) : '_all';
    if ($type == '_all') {
        $type = explode(',', siteorigin_widget_post_selector_all_post_types());
    }
    $results = array();
    $r = new WP_Query(array('s' => $term, 'post_status' => 'publish', 'posts_per_page' => 20, 'post_type' => $type));
    foreach ($r->posts as $post) {
        //			$thumbnail = wp_get_attachment_image_src($post->ID);
        $results[] = array('label' => $post->post_title, 'value' => $post->ID);
    }
    header('content-type:application/json');
    echo json_encode($results);
    exit;
}