Is it possible to use the get_posts function within a function?
-
Is it possible to use the get_posts() function within a function as below? I am trying to print the latest posts within the body of an html heredoc email template. Everything prints fine on a plugin page in the dashboard when the code is not placed within the function. But if create a function (getnews) and call
getnews()
nothing prints.<?php function getnews() { $args = array( 'numberposts' => 10, 'order'=> 'ASC', 'orderby' => 'title' ); $postslist = get_posts( $args ); foreach ($postslist as $post) : setup_postdata($post); ?>
<?php the_date(); ?><?php endforeach; } ?>
<?php the_title(); ?> <?php the_excerpt(); ?>For the heredoc attempt I have
$newsletter = 'getnews';
and refer to it so:{$newsletter()}
without success.Thanks for any help sorting this out.
- The topic ‘Is it possible to use the get_posts function within a function?’ is closed to new replies.