i am creating a plugin.
i want to get all post like title and url. Not on frontpage just admin panel.
when i try to use this but not working
<?php
$args = array( 'numberposts' => -1);
$posts= get_posts( $args );
if ($posts) {
foreach ( $posts as $post ) {
setup_postdata($post);
the_title();
}
}
?>
Please try this
You must pass a reference to the
global $post
variable, otherwise functions likethe_title()
don’t work properly. So above$args
:Also, use
wp_reset_postdata()
to restore globals to the original state when complete.