Skip to content

Instantly share code, notes, and snippets.

@hemraj7171
Last active January 5, 2017 11:34
Show Gist options
  • Save hemraj7171/42261bec5e1e2c52691f16a1c1ceb0e1 to your computer and use it in GitHub Desktop.
Save hemraj7171/42261bec5e1e2c52691f16a1c1ceb0e1 to your computer and use it in GitHub Desktop.
Display single post with slug on other pages
<?php
/*
* Template Name: Test Page
*
*/
//please change this as your wish
// you can inser the post slug which you want to render
$post_slug = 'the-new-post_slug';
//query args
$args = array(
'post_type' => 'post',
'name' => $post_slug
);
$myposts = get_posts( $args );
/*
* Now $myposts have all the info of $post_slug
*/
foreach ( $myposts as $post ) : setup_postdata( $post );
//title of the post
the_title();
//content of the post
the_content();
//featured image of the post
the_post_thumbnail();
endforeach;
//reset the current query
wp_reset_postdata();
/*
* Note : Please create new test page and assign this template and enjoy.
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment