List posts from outside a multisite blog
To make a long story short, I need to create a .php-file that fetches the permalinks to all the published posts on one of my blogs. I need to be able to direct link to the .php-file without any login, since it is going to be used for a cronjob.
To describe my setup, I’m using WordPress 3.0 with multisite activated, and I need to get the posts from the blog with the virtual subfolder /blog. Lets say that WordPress is installed on http://www.example.com along with several blogs in the network, and that the blog I need to retrieve the posts from is accessed at http://www.example.com/blog.
At first, I put the .php-file in the WordPress root (www.example.com), included wp-blog-header.php, and ran a custom loop in order to fetch all the published posts without any paging. Of course, the script couldn’t know that I wanted the posts from http://www.example.com/blog so the result was blank. Because the /blog subfolder is virtual and doesn’t exist in reality, I cannot put the .php-file in there.
My second try was to put the .php-file inside the theme folder (www.example.com/wp-content/themes/my-theme), and then access it from http://www.example.com/blog/file.php, but then the WordPress security mechanism kicked in and returned a 404-error.
My third try was to use $wpdb to get the rows, which at first seems to work. But since I need to fetch the permalink to each post (and I’m using fancy permalinks by the way), I would need to create quite a lof of complex queries (or at least one really complex) to spider through the way WordPress connect posts with the category and so on.
So, after several hours of tearing my hair off, I’m asking you for help. Any ideas how to solve this problem?
- The topic ‘List posts from outside a multisite blog’ is closed to new replies.