Problem with context in multisite – getting main site data in every blog (get_pages())

I’m working on a multisite, everything is configured and works fine from dashboard.
Now I’m trying to write a plugin with a PHP file that displays the list of pages created in a site – to be displayed to the admin of the site who logs in.

Here is the code (simplified)

Read More
<?php
require('../../../wp-load.php');
?>
(some HTML)
<?php    
    $pages = get_pages();                                  

    foreach ( $pages as $page ) {
        echo $page->post_title . '<br>'
?>

My plugin PHP file uses login_redirect filter to redirect user after login to that PHP file where I am trying to display the list of pages the user created:

function my_login_redirect( $redirect_to, $request ) { 
    return '/wp-content/plugins/my-admin-plugin/my-admin-view-all-pages.php'; 
}

THE PROBLEM – no matter which site I’m in, I get the list of pages created in the “main” site. How do I pass the context of the existing site to the functions?

Related posts

Leave a Reply

1 comment

  1. The way you are doing this is not correct.

    Two possibilities:

    1) Create a Dashboard Widget to display the information

    add_action('wp_dashboard_setup', 'wpse_60096_dashboard_widget');
    
    function wpse_60096_dashboard_widget() {
        if( current_user_can( 'activate_plugins' ) )
            wp_add_dashboard_widget( 
                'wpse_60096', 
                'Site Pages', 
                'wpse_60096_add_widget_content'
            );
    }
    
    function wpse_60096_add_widget_content() {
        $pages = get_pages();                                  
        foreach ( $pages as $page ) 
            echo $page->post_title . '<br>'; 
    }
    

    2) Register an invisible submenu page