network-wp-query
network-wp-query copied to clipboard
Definitely does NOT work
I've a multisite wp. On a certain site, I've created a static page (let's say page id 179) where I want to show posts from all network. I've set this page as the blog page in WP dashboard.
Now, I tried all the techniques here: https://presscustomizr.com/snippet/three-techniques-to-alter-the-query-in-wordpress/
with no luck.
The simplest (that doesn't work):
add_action( 'template_redirect', 'hooks_setup' , 20 );
function hooks_setup() {
if ( is_page(179) )
{
add_action( '__before_loop' , 'set_my_query' );
add_action( '__after_loop' , 'set_my_query', 100 );
}
else return;
}
function set_my_query() {
global $wp_query, $wp_the_query;
switch ( current_filter() ) {
case '__before_loop':
$wp_query = new WP_Query( array(
'network' => true
) );
break;
default:
$wp_query = $wp_the_query;
break;
}
}