• When I’m writing a post in WordPress and try to get a preview of my post, I keep getting this error: Sorry, no posts matched your criteria.

    The post is in the database, I’ve checked that, so since that’s not the case, I’m trying to find the function or file where the post is actually fetched from the database.

    I’ve started from the beginning with the file wordpress.php and tracked the flow to the file wp-settings.php. From here I don’t know where to look.

    The flow from wordpress.php to wp-settings.php is like this: wordpress.php -> wp-blog-header.php ->wp-load.php -> wp-config.php -> wp-settings.php

    There are a number of function calls from wp-settings.php. Which is the essential one?

    Can anyone tell me where to look to find where the fetching from the database is executed?

Viewing 13 replies - 1 through 13 (of 13 total)
  • If you have a post preview problem and haven’t already hacked any of the core files, I’d suggest that you start troubleshooting by:

    – deactivating all plugins to see if this resolves the problem. If this works, re-activate the plugins one by one until you find the problematic plugin(s).

    – switching to the default theme to rule out any theme-specific problems.

    – increasing the memory available to PHP
    http://wordpress.org/extend/plugins/memory-bump/
    http://wordpress.org/support/topic/253495#post-1017842

    Thread Starter torvad

    (@torvad)

    I think it’s a good idea, and I will try it if I can’t find the error, but I really want to see what’s wrong.

    So if you know, could you please tell me which file or function is called from wp-settings.php in order to fetch the post from teh database.

    I know that somewhere down the road you end up in the WP_Query class or soething like that, but I can’t figure out where to go from wp-settings.php.

    And I think php is really hard to debug compared to Java…

    Switch theme, i’d have about 80% certainty the issue lies there, please confirm if that helps (you only switch for 5 minutes or less to test the preview link – you can switch back afterward).

    Beyond a theme issue, next plugins..

    Follow the suggestions provided and you’ll find the source of your problem.. 😉

    Thread Starter torvad

    (@torvad)

    I’m using a theme I have customized myself…

    Do you mean I should change theme just for the time it takes to look at the preview? In case I don’t know if I like the solution. Even if it’s only for a couple minutes my blog will look different for that time, and that would be a bit unprefessional…

    There has to be someone who which function is called from wp-settings.php!!!

    I don’t personally think anything in that file is at fault, what reasoning is there to suggest that file is the cause of the problem?

    Thread Starter torvad

    (@torvad)

    Well I’d like to find the error so I can fix it…
    It must be possible to trace the function calls!

    I don’t think wp-settings.php is the problem. The error must be in a function or file that is called from wp-settings.php.

    The error message I get “Sorry, no posts matched your criteria.” is printed from the file single.php. The error happens because the function have_posts() returns false… I will check if the post is fetched from the database…

    And the easiest way to determine the root of said problem is to switch theme and disable plugins, it’s standard procedure for dealing with pretty much any WordPress problem.

    If you can’t afford to be switching theme then you really shouldn’t be making customizations on the live site to begin with (but what’s done is done, so let’s move on).

    I’m fairly code savy, but you’re not giving me much to work with here….

    Start with plugins instead, disable one(or a couple) at a time and then test if previews work. Once you’ve done that if previews are still not working you’ve at least ruled out something.

    Thread Starter torvad

    (@torvad)

    But Mark, is the following right? When WordPress displays a post index.php is first run followed by these files in the following order: wp-blog-header.php ->wp-load.php -> wp-config.php -> wp-settings.php

    Since a post should be displayed, there must be a fetch from the database. So from wp-settings.php a file or a chain of files must end up in a function that fetches the post from the database. Which function does this?

    Another thing.
    Which file or function eveluates the url and determines if a post or posts from a section should be displayed?

    But Mark, is the following right? When WordPress displays a post index.php is first run followed by these files in the following order: wp-blog-header.php ->wp-load.php -> wp-config.php -> wp-settings.php

    Sounds about right, yes..

    Since a post should be displayed, there must be a fetch from the database. So from wp-settings.php a file or a chain of files must end up in a function that fetches the post from the database. Which function does this?

    WP_Query is the main WordPress query class.
    http://codex.wordpress.org/Function_Reference/WP_Query

    Beyond that, the functions that actually do the selection are methods of the WPDB class.
    http://codex.wordpress.org/Function_Reference/wpdb_Class

    NOTE: Personally when i’m tracking down code i tend to go straight to the source (as in the source code), i find i get the information/answers i need alot faster that way.

    Thread Starter torvad

    (@torvad)

    Thanks a lot Mark!

    Beyond that, the functions that actually do the selection are methods of the WPDB class.
    http://codex.wordpress.org/Function_Reference/wpdb_Class

    I will try to look in WPDB class for the function that fetches the post from the database.

    Thread Starter torvad

    (@torvad)

    I found out why the preview is not working.

    In WP_Query the function is_user_logged_in() returns false. This function is defined in pluggable.php where it calls wp_get_current_user() that returns the global variable $current_user.

    It seems strange that this variable is empty since I’m logged in.

    When you log into WP, in which class is $current_user given a value?

    I’m using WP 2.9.1.

    $current_user is typically set using..

    $current_user = wp_get_current_user();

    Both wp_get_current_user() and wp_set_current_user() are defined in…
    http://core.trac.wordpress.org/browser/tags/2.9.1/wp-includes/pluggable.php

    The WP_User class can be found in..
    http://core.trac.wordpress.org/browser/tags/2.9.1/wp-includes/capabilities.php

    NOTE: There’s an action in the wp_set_current_user() function, perhaps you have a plugin installed that hooks onto that action and does something, and perhaps does so incorrectly (just something to consider).

    Thread Starter torvad

    (@torvad)

    I see. In pluggable.php the current_user gets id = 0, which I guess means that the user is not logged in.

    When I display the blog posts, edit.php in wp-admin folder is called and if I put this code in top:

    global $current_user;
    echo “print user id: ” . $current_user->ID;

    the id is displayed…

    Could it be that a file should be included?

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Problems with preview’ is closed to new replies.