limitPerCategory; $autocomplete = array(); foreach($asl_options->allowedPostType as $post_type): /* get $max_cat posts which are contained post_type $post_type */ $args = array( 'admin_searchlight_like' => "%".$_POST['q']."%", 'post_type' => $post_type, 'posts_per_page' => $max_cat, 'post_status' => 'publish, pending, draft, future, private' ); query_posts($args); $results = array(); $post_type_object = get_post_type_object($post_type); while(have_posts()): the_post(); $results[] = array( 'url' => "post.php?post=".(get_the_ID())."&action=edit", 'name' => get_the_title(), 'icon' => $post_type_object->menu_icon); endwhile; /* if there are more $max_cat results, we add a direct link which redirects to post type page */ if ( $wp_query->found_posts > $max_cat ) $results[] = array( 'url' => "edit.php?post_type=".$post_type."&s=".$_GET['q']."&post_status=all&mode=list", 'name' => "Voir plus de résultats...", 'icon' => $post_type_object->menu_icon ); /* get label */ $autocomplete[] = array( 'title' => $post_type_object->label, 'results' => $results ); endforeach; $json = json_encode($autocomplete); print $json; endif; exit(); ?>