WordPress.org

Ready to get started?Download WordPress

Forums

Fatal error: Call to a member function set_prefix() (16 posts)

  1. Aldarion
    Member
    Posted 6 years ago #

    Hello everyone

    I am trying to display posts outside of my WP by using the following code:

    <?php require('wp-blog-header.php'); ?>
    <?php query_posts('showposts=3'); ?>
    
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    	<div class="post" id="post-<?php the_ID(); ?>">
    		blabla / loop
    	</div>
    <?php endwhile; ?>
    <?php endif; ?>

    saved as newest.php in the WP folder, which resides under domain/blog/. The file works just as intented when I open it. But then I am trying to include that file into my CMS, which resides under domain/cms/

    include("../blog/newest.php");

    and I get the following error message:

    Fatal error: Call to a member function set_prefix() on a non-object in /www/htdocs/w008c40e/blog/wp-settings.php on line 209

    I have searched this forum, googled, but I can't come up with a solution to this problem. Could it be that the CMS (made simple) and WP just can't get along? Thank you very much for your help.

  2. Ryan Christenson
    Member
    Posted 6 years ago #

    I'm doing something similar and getting the same error.

    Did you ever solve the problem?

  3. intinig
    Member
    Posted 6 years ago #

    Same problem here. if make up a plain php file like this one:

    <?php
    require_once('wp-config.php');
    ?>

    I get the same error. Any clue?

  4. bookchiq
    Member
    Posted 6 years ago #

    Running into the same thing. Pulling the include from the same directory (root of the blog) seems to work, though.

  5. ruiloure
    Member
    Posted 6 years ago #

    Hello,

    as anyone found a solution for this problem? I´m stuck with with for a long time now and it would be really helpful do know the solution.

  6. zonax
    Member
    Posted 6 years ago #

    i have the same error .. dam it ... what happens whit wordpress ? .. because the previews version .. what much bether :(

  7. hotkee
    Member
    Posted 6 years ago #

    Just fot the hell of it, I just tried it as per Aldarion's code, no problem, works fine.

    I get this printed out

    blabla / loop
    blabla / loop
    blabla / loop

    Might be you guys have been tweaking some files or check your table prefix is set in wp-config or something.

  8. bookchiq
    Member
    Posted 6 years ago #

    Thanks for the feedback, hotkee. Can you confirm you tried it from a directory outside of WordPress?

    For instance, my setup has WordPress in the root of the domain, and I don't get the error if I try to include from there, but I have an "ads" subdirectory (which is the location I really need to call from) and that's when I get the error.

    I can confirm that I have standard table prefix (and it's listed in the wp-config.php file) and no core mods at all.

  9. hotkee
    Member
    Posted 6 years ago #

    I did this

    <?php require('../home/wp-blog-header.php'); ?>
    <?php query_posts('showposts=3'); ?>
    
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    	<div class="post" id="post-<?php the_ID(); ?>">
    		blabla / loop
    	</div>
    <?php endwhile; ?>
    <?php endif; ?>

    my install is /home
    created /h2 and put a file in there and it works fine
    also amended it to be called from / and works

  10. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Do not include the config file directly. Include the wp-blog-header.php file instead.

  11. shemeermali
    Member
    Posted 6 years ago #

    i have included wp-blog-header.php

    but getting same error

  12. jonnybradley
    Member
    Posted 5 years ago #

    Hi all

    I'm now getting the same thing (WP 2.6.2)

    WP works fine when i go to it's page (or admin etc), but this is being included in another PHP app (which i didn't write) and it seems it looses the "global-ness" of $wpdb, hence it being a non-object (actually uninitialized).

    If i declare "global $wpdb" in the function that includes "wordpress/wp-blog-header.php" it gets past this problem but fails later on the $wp object, for the same reason (and the same hack doesn't fix it)

    I think it's something to do with the directory structure of the site - index.php includes "classes/class.php", which includes "wordpress/etc" and when it then gets inside "wordpress/wp-includes" the scope of what's global changes... and i'm stumped too (sorry).

    I'll carry on kludging (going to play with includes/requires), but if anyone knows more... we'd all be ever so grateful!

    Yours, hoping...

    jonny B

  13. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    If you're including WordPress from another app, then you have to include it from the global scope, and not a function scope. WordPress expects to be in global scope when in the main application, if you include it from inside a function, all the scoping changes.

  14. jonnybradley
    Member
    Posted 5 years ago #

    Hmm - found a sort of fix for me (typical! :)

    I moved the include/require statement out of the function it was in (seemed to work ok with old WP - 2.1 i think) and into the global scope (like in index.php). This is because everything that's declared in a file included inside a function is local to that function (i RTFM'd some more)

    Hope that's a clue enough for others - now i must get on, that that's just about wasted my day!

    jonny

  15. fattyjules
    Member
    Posted 5 years ago #

    My solution is similar to the post above.

  16. Libellule24
    Member
    Posted 5 years ago #

    So far, it work out well for me. I've got the following code:

    <div>
    <?php require('../httpdocs/blogue/wp-blog-header.php'); ?>
    <?php query_posts('showposts=5'); ?>
    
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    	<div class="post" id="post-<?php the_ID(); ?>">
    loop.
    	</div>
    <?php endwhile; ?>
    <?php endif; ?>
    </div>

    in a file called colonex.php. I include this file on my index.php with a basic include command. But now I'm a wrench.
    The "loop." appears as many times as I want it to. (I'm pretty new to this, so please dont hit me!)
    But how do I replace it with my posts?
    (told ya...)

Topic Closed

This topic has been closed to new replies.

About this Topic