I having hard time to make work the plugin Virtual Pages (WordPress plugin to ease the creation of virtual pages)

I did have edit to create a loop based on a query.

add_action( 'gm_virtual_pages', function( $controller ) {
/* Creating virtuals pages for companies */ 
$args = array( 'post_type' => array('companies',), 'post_status' => array('publish',), );
$the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();

   // Creations des pages
   $controller->addPage( new \GM\VirtualPages\Page( '/companies/'.$the_query->post->post_name.'/about' ) )
     ->setTitle( 'About Us' )
     ->setContent( get_the_content() )
     ->setTemplate( 'custom-page.php' );


custom-page.php is in the child theme folder, and the controller in the root theme. I did have tried to put all the file in the parent theme, but it's the same.

I took the exact code download, minus one virgule at the section "how tu use".

$controller->addPage( new \GM\VirtualPages\Page( "/custom/page" ) )
 ->setTitle( 'My First Custom Page' )
 ->setContent( '<p>Hey, this is my first cutom virtual page!</p>' );
 ->setTemplate( 'custom-page.php' )

Line 3, the is no ; at the end. Rather than that everything is the same. I check the download code and the published / commented code.

  • $Title is returning "About US"
  • $content is returning the post content but
  • $Template is returning page.php, and if im right, it should return custom-page.php, or at least, if it's an inclusion, i should see the content of custom-page.php in the page.

I followed all process, read everything, but still not working. Anyone as any hint to fix this, before me passing to another method ?

  • Out of interest, why aren't you using natural permalinks for your custom post type? Feb 19, 2015 at 12:00
  • 1
    Because the main objective is to create a Website generated once a child template is activated. The content to fill pages are directly coming from a custom post type. Ex : I create a company, from a custom post type, and from there, a full company website is generated, with virtual pages without having to create post page. Feb 19, 2015 at 14:06
  • 2
    Have you read the affiliated answer? The explanation there is pretty good. Aside from that the semicolon has to be after the last method call, the way you show it in your question you should get an error. Feb 19, 2015 at 17:39

1 Answer 1


I'm the author of that plugin and I can confirm there was an issue.

It was in the GM\VirtualPages\TemplateLoader::init(); method.

Issue was caused by an untested switch from array_merge to wp_parse_args.

They are similar, but I would have to inverse order of arguments moving from one to the other. Shame on me.

I fixed that in the Gist (source) now it should work.

  • Strange. no i have an error installing the plugin. Parse error: syntax error, unexpected T_STRING in ..../wp-content/plugins/gm-virtuals-pages/gm-virtual-pages.php on line 1 Mar 7, 2015 at 14:43
  • @groupe-wibi that file has not been modified at all. Are you sure you have PHP 5.3+?
    – gmazzap
    Mar 7, 2015 at 16:08
  • Nop. 5.2+ ;( Can i adapt it ? Mar 8, 2015 at 15:41
  • @GroupeWibi First of all you need to remove all namespaces and add a prefix to all classes and interface names (of course, that suffix have to be added everywhere in the file where names appear). After that you need to replace anonymous functions with named ones in gm-virtual-pages.php. BTW note that PHP 5.2 reached its end of life in 2011(!) it means it's unsecure, far slower than newer versions and, as you experienced, feature missing. I strongly suggest you to change hosting: your are paying for garbage if they do not offer 5.4+ PHP version.
    – gmazzap
    Mar 8, 2015 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.