Calling wp-blog-header.php from inside a PHP function
-
Heyas, I’m trying to get lastest WP blog posts into my site’s front page using wp-blog-header.php.
The problem is that I get this error if I have the code inside a function:
Fatal error: Call to undefined method stdClass::set_prefix() in /wordpress/wp-settings.php on line 268
If I put the same code straight into some empty file, it works, returning the news. If I put the same code inside a function, it fails. So, basically it only works if it’s in the “root” of the php file. The main problem of course is that the site I’m working with is made so that everything is basically being run inside a function call.
The full PHP code:
loadItAll(); function loadItAll() { require_once('wp-blog-header.php'); $myposts = get_posts('numberposts=5&offset=1&category=1'); foreach($myposts as $post) : ?> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br /> <?php endforeach; }
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Calling wp-blog-header.php from inside a PHP function’ is closed to new replies.