treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Network wordpress site with custom query issue.

  • I have a custom query for my network site home page that pulls in all the recent post of the all the blogs. Wordpress realizes that I don't have post for that specific blog so after the first page all my additional pages return 404 but the query is still displayed. The root cause is the wp_class.php function handle_404 (). Does anyone have a work around that might assist with my situation. Or how do I overwrite the wp_query to use my query temporary for that page.

    function get_eh_all_grp_recent_post($blog_list){
        global $wpdb;
        $other_sqlstr = '';
        $limitstr = '';
        $uni = '';
    
        foreach ($blog_list AS $blog) {
          if ($other_sqlstr != '')
            $uni = ' union all ';;
          if($blog['blog_id'] == 1) {
            $other_sqlstr .= $uni . " (SELECT ".$blog['blog_id']." as blog_id, id, post_date from wp_posts where wp_posts.post_status = 'publish' and wp_posts.post_type = 'post' and wp_posts.post_title <> '".__('Hello world!')."')";
          }
          else {
            $other_sqlstr .= $uni . " (SELECT ".$blog['blog_id']." as blog_id, id, post_date from wp_".$blog['blog_id']."_posts where wp_".$blog['blog_id']."_posts.post_status = 'publish' and wp_".$blog['blog_id']."_posts.post_type = 'post' and wp_".$blog['blog_id']."_posts.post_title <> '".__('Hello world!')."' )"; 
          }     
        }
    
          //$limit = ' LIMIT '.$start_page.', 10';
        $other_sqlstr .= " ORDER BY post_date desc ";// . $limit;
    
        $grp_recent_posts = $wpdb->get_results($other_sqlstr, ARRAY_A);
          //echo $wpdb->print_error();
    
        return $grp_recent_posts;
      }
    
  • I am now using wp_multisite_query in hopes to solve the issue but I am still getting a 404 error on page 2.