Render template multiple times per page?
-
I’m running a Timber-based theme on a multisite. I would like to extend my site search functionality to show search results from every site in the network. I have the following code in my
search.php
:if ( is_multisite() && isset( $_REQUEST[ 'multisite' ] ) && $_REQUEST[ 'multisite' ] ) { $search_for = get_search_query(); $sites = get_sites(); foreach ( $sites as $site ) { switch_to_blog( $site->blog_id ); $query = new \WP_Query( $search_for ); $context['title'] = 'Search results for "' . get_search_query() . '"'; $context['site_name'] = get_bloginfo(); $context['posts'] = new Timber\PostQuery( $query ); Timber::render( $layout_template, $context ); restore_current_blog(); } } else { $context['title'] = 'Search results for "' . get_search_query() . '"'; $context['posts'] = new Timber\PostQuery(); Timber::render( $layout_template, $context ); }
Note that I’m calling
Timber::render()
multiple times in a single page load. Stepping through in the debugger I see the loop is executing once per site. Unfortunately, the template is only rendered for the first site.How do I render the same template multiple times for a single page request?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Render template multiple times per page?’ is closed to new replies.