how to get post data outside loop in wordpress

how to get post data outside loop in wordpress

WordPress hack, In this wordpress tutorial we given code and shown, how to get post data outside loop in wordpress. In wordpress theme you can get post data.

how to get post data outside loop in wordpress

Outside the loop you can get the a post data. you just need to copy paste following code in your theme file.

<?php
global $post;

$args = array( 'numberposts' => 5, 'offset'=> 1, 'category' => 1 );

$myposts = get_posts( $args );

foreach( $myposts as $post ) : setup_postdata($post); ?>
 <li>
 <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
 </li>
<?php endforeach; ?>
how to get post data outside loop in wordpress
how to get post data outside loop in wordpress

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.