In my Wordpress site, I am trying to retrieve the most recent 10 posts and store them in a string. After that I will write this content into a text file. Below is the code I am using.
<?php $str = ''; ?>
<?php
require_once('../wp-blog-header.php');
query_posts('&showposts=10&order=DESC&caller_get_posts=1');
while (have_posts()) : the_post(); ?>
<?php $str .= '<a href="' . the_permalink() . '">' .the_title() . '</a>'; ?>
<?php endwhile; ?>
<?php $fp = fopen("latestposts.txt", "w");
fwrite($fp, $str);
fclose($fp);?>
The problem is, when I execute this page, the permalink and title are returning in this page and empty ''....'' tags are coming in text file. If I am not using the string, the href tags are returning correctly in the same file.