I am trying to reuse content from my static front page in a different page template. But because my front page is static, I can not call it by page name. Is it possible to call the front page another way? Preferably not by ID! My code:

    <?php $my_query = new WP_Query('pagename=front');
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID;?>           
    /* The content I want from the front page content */
    <?php endwhile; ?>   
  • If you're using a Page - a static front page - call it by post ID rather than by pagename.
    – WebElaine
    Jan 9 '18 at 17:10
  • @WebElaine - thanks - yea ID works, but I would like to call it some other way, because it is a staging site - so when I change it to a live site on a different server the ID might change.
    – Cody
    Jan 9 '18 at 17:16
  • The answer here may help you - use the slug ('front') and 'post_type' 'page'. stackoverflow.com/questions/14979837/…
    – WebElaine
    Jan 9 '18 at 19:06

Using get_option() you can get the page that is assigned to the front page:

$frontpage = get_post(get_option('page_on_front'));

Or as you have it:

$my_query = new WP_Query( array( 'page_id' => get_option('page_on_front') ) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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