• 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

    (@johnpfree)

    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.