Skip to content

Definitely does NOT work #13

@jasmines

Description

@jasmines

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;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions