Title: ob_* problems using wp-load and query_posts() outside WordPress
Last modified: August 20, 2016

---

# ob_* problems using wp-load and query_posts() outside WordPress

 *  [johnpfree](https://wordpress.org/support/users/johnpfree/)
 * (@johnpfree)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/ob_-problems-using-wp-load-and-query_posts-outside-wordpress/)
 * I wish to display specific posts outside WP in my own app.
 * I’ve made a simple PHP testapp that does this and works great, HOWEVER…
    my real
   app uses a trailing edge but quite functional **templating system depending on
   string substitution**, so the default behavior of echoing the content at the 
   point of the call doesn’t work.
 * Solution: use the PHP Output Control Functions. HOWEVER…
    my template object 
   is trashed afterwards.
 *     ```
       define('WP_USE_THEMES', false);
       require('../wptest/wp-load.php');
       query_posts("p=289");
       $this->template->set_var("TITLE", 'test4');	 // templating object working normally
       ob_start();
       	while (have_posts()): the_post();
       		the_content();
       	endwhile;
       $myStr = ob_get_contents();
       ob_end_clean();
       $this->template->set_var("TITLE", 'test5');	 // templating object is trashed with:
       // "Fatal error: Call to a member function set_var() on a non-object ..."
       ```
   
 * any clues on how this messes up my template?
    Oh, the ob_ code DOES work – my
   post IS correctly in $myStr, ready to use if only my template object was intact!
   🙂

Viewing 1 replies (of 1 total)

 *  Thread Starter [johnpfree](https://wordpress.org/support/users/johnpfree/)
 * (@johnpfree)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/ob_-problems-using-wp-load-and-query_posts-outside-wordpress/#post-3227233)
 * update! It is **the $this pointer** that got screwed up, not the $this->template
   pointer. my bad.
 * I am able to kind of fix myself and limp forward by _saving $this BEFORE the 
   ob\_* sequence, and using the saved version afterwards_.
 * So I am good in terms of moving forward on my work, but if anyone has thoughts
   on _why the code above would destroy $this_, that would be good to know!
 * thanks

Viewing 1 replies (of 1 total)

The topic ‘ob_* problems using wp-load and query_posts() outside WordPress’ is closed
to new replies.

## Tags

 * [ob_get_contents](https://wordpress.org/support/topic-tag/ob_get_contents/)
 * [outside wordpress](https://wordpress.org/support/topic-tag/outside-wordpress/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [johnpfree](https://wordpress.org/support/users/johnpfree/)
 * Last activity: [13 years, 6 months ago](https://wordpress.org/support/topic/ob_-problems-using-wp-load-and-query_posts-outside-wordpress/#post-3227233)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
