Build Search Shortcode for Essential Grid
Easiest way is to create or rebuild your theme’s search.php.
What you need are the resulting post IDs. You could use the usual loop to get them but we recommend building your own query which also gives you the possibility to define the post types in which you will search among several other options (check the codex: https://codex.wordpress.org/Class_Reference/WP_Query).
1 2 3 4 5 6 7 8 9 |
// Build Search Query $args = array( 's' => $_REQUEST['s'], 'showposts' => -1, 'post_type' => $searchable_types // define searchable Post Types ); $tp_allsearch = new WP_Query($args); |
After building the appropiate Query you run through a custom loop that adds the post id to a pre defined array.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$posts = array(); // If there are Search posts if($tp_allsearch->have_posts()) : // Go through result while($tp_allsearch->have_posts()) : $tp_allsearch->the_post(); // Save Post ID in array $posts[] = $post->ID; endwhile; else: return false; endif; |
When finished with collecting all resulting post IDs you can include the following Essential Grid Shortcode. The posts parameter is filled with the array of IDs collected before, the alias is one grid you build for this purpose (here our example search default grid). Please remember that you need to select the categories and tags you might want to filter the posts with.
1 2 3 4 5 6 7 |
// Build shortcode with the $post array build before $the_content = do_shortcode('[ess_grid alias="searchdefault" posts="'.implode(',', $posts).'"]'); // Echo Out the result in your page echo $the_content; |