Query for combining posts on a Multisite Network and displaying a custom pagnition

For a long time now I’ve been trying to combine queries from 3 different sites on a WordPress multisite on the same network. Yes all sites off the 1 network that lives on the 1 server.

This is the queried solution to the problem that also lists a way to display pagination, though I haven’t worked out how to run the pagination SEO just yet. I was not able to figure out how to use WP’s default pagination in this scenario.

If you have a suggest please let me know


//Setting up a query
$query = new WP_Query($args);

//Listing all site ID's
$sites = array( 1, 2, 3 );

//Setting up empty array list
$all_posts = array();

//Querying all posts in the argument
$args = array( 'post_type' => 'post', 'order' => 'DESC');

// Looping all the sites and compiling posts in the array $all_posts
foreach( $sites as $site ) {
 switch_to_blog( $site );
 $posts = get_posts( $args );
 foreach( $posts as $post ) {
 // Better get the post's permalink, since it's site-dependent
 $post->permalink = get_permalink($post->ID);
 $all_posts[] = $post;
 //restoring to the default blog

//sorting posts using the sort funtion
$all_posts = sort_posts($all_posts);

//manually setting the number of page articles
$nb_elem_per_page = 8;

//manually setting the $paged item
$page = isset($_GET['page'])?intval($_GET['page']-1):0;

//calculating the number of paged elements
$number_of_pages = intval(count($all_posts)/$nb_elem_per_page)+2;


<div class="row">

 $i = 1; // row item counter
 $m = 2; // default max per row

//displaying all posts with pagination to follow

 foreach( array_slice($all_posts,$page*$nb_elem_per_page,$nb_elem_per_page) as $post ){
 //while ( have_posts() ) { the_post(); ?>
 <div class="col-md-6">
 <div class="item">
 <?php echo generateImage(get_the_post_thumbnail_src(get_the_ID(),'intro-image-small'),'',$post->permalink); ?>
 <div class="content">
 <?php get_template_part( 'assets/partials/default', 'info' ); ?>
 <h2><a href="<?php echo $post->permalink; ?>"><?php the_title(); ?></a></h2>
 <div class="text">
 <?php echo get_the_excerpt (); ?>
 <?php if($i==$m){ ?>
 <div class="clearfix"></div>
 <?php $i = 1; }else{
 } ?>

<div class="pagination">
 <div class="numbers">
 <nav class="navigation pagination" role="navigation">
 <div class="nav-links">

 <?php if($_GET['page'] > 1){ ?>
 <a href='./?page=<?php echo $_GET['page']-1; ?>' class="page-numbers">Newer</a>
 <?php } ?>

 for($i=1;$i<$number_of_pages;$i++){ ?>
 <?php if($i != $_GET['page']){ ?><a href='./?page=<?php echo $i?>' class="page-numbers"><?php }else{ ?><span class="page-numbers current"><?php } ?>
 <?php echo $i; ?>
 <?php if($i != $_GET['page']){ ?></a><?php }else{ ?></span><?php } ?>
 <?php } ?>

 <?php if($_GET['page'] < ($number_of_pages-1)){ ?>
 <a href='./?page=<?php echo $_GET['page']+1; ?>' class="page-numbers">Older</a>
 <?php } ?>


<?php wp_reset_query(); ?>

Using query_posts( ) on a page for simple arguments

I wanted an easy but simple way to just edit the query on the home.php page without going into complicated paging parameters and take advantage of just manipulating WP powerful default query.

Use this on the page with your own set of arguments to filter the main WP_Query.

query_posts( $args );

MPC Flip Book WordPress Plugin Migration problem

The MPC Flip book WordPress plugin is just awesome. Works right out of the box without any hassles.

However we had one major problem. We could not migrate wordpress from a development server locally to a production environment. Simply looking up the links and changing it did not do the trick.

So we approached MPC via a ticket and this was their response:

"Flipbook is using serialized array (http://php.net/manual/en/function.serialize.php ).

Simple search & replace method, while transferring Flipbook settings is not enough. The data are saved as a serialized array.  This method include a string length parameter inside the saved data. So, this value has to be adjusted after changing the string length (for example domain name)."

And they recommend the following steps which worked like a charm.
Before you proceed remember, backup your backups and then try this out:

  1. Download a copy of  ‘wp_options.sql’
  2. Use a service like:
    which essentially searches and replaces serialized code.
  3. Once at the link:
    1. Enter link to be replaced
    2. Enter the new link
    3. enter the security number
    4. Upload the wp_options.sql file
    5. Click Process MySql
    6. And your new SQL file should automatically download
  4. Delete the old ‘wp_options.sql’ and upload the new ‘wp_options.sql’ file with the newly serialized SQL File.

These steps did it for us. And now everything works just fine.

WordPress migrating images problem

When moving a website from local to staging, a major problem was identified. Images that were used in content pages (POSTS) in wordpress were being broke. After looking through 100’s of articles, and reading 100’s of discussions I’ve come to the conclusion that WordPress just works with Relative paths rather than absolute paths for their images.

And there was no work around to the issue, no filters, script or actions that I could find.

The only solution I could find was running a MYSQL Query.

UPDATE wp_posts SET post_content=(REPLACE (post_content, '<old url>','<new url>'));

This was the best solution I could find.

Use this code to hide text editor on certain pages or templates

/** Hide editor on specific pages. */
add_action( 'admin_init', 'hide_editor' );
function hide_editor() {
  // Get the Post ID.
  $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
  if( !isset( $post_id ) ) return;
  // Hide the editor on the page titled 'Homepage'
  $homepgname = get_the_title($post_id);
  if($homepgname == 'Homepage'){ 
    remove_post_type_support('page', 'editor');
  // Hide the editor on a page with a specific page template
  // Get the name of the Page Template file.
  $template_file = get_post_meta($post_id, '_wp_page_template', true);
  if($template_file == 'my-page-template.php'){ // the filename of the page template
    remove_post_type_support('page', 'editor');