Title: Problems with preview
Last modified: August 19, 2016

---

# Problems with preview

 *  [torvad](https://wordpress.org/support/users/torvad/)
 * (@torvad)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/problems-with-preview/)
 * 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)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/problems-with-preview/#post-1664599)
 * 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/extend/plugins/memory-bump/)
   [http://wordpress.org/support/topic/253495#post-1017842](http://wordpress.org/support/topic/253495#post-1017842)
 *  Thread Starter [torvad](https://wordpress.org/support/users/torvad/)
 * (@torvad)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/problems-with-preview/#post-1664696)
 * 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…
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/problems-with-preview/#post-1664697)
 * 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](https://wordpress.org/support/users/torvad/)
 * (@torvad)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/problems-with-preview/#post-1664700)
 * 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!!!
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/problems-with-preview/#post-1664701)
 * 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](https://wordpress.org/support/users/torvad/)
 * (@torvad)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/problems-with-preview/#post-1664702)
 * 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…
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/problems-with-preview/#post-1664704)
 * 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](https://wordpress.org/support/users/torvad/)
 * (@torvad)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/problems-with-preview/#post-1664784)
 * 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?
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/problems-with-preview/#post-1664788)
 * > 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](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](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](https://wordpress.org/support/users/torvad/)
 * (@torvad)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/problems-with-preview/#post-1664830)
 * 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](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](https://wordpress.org/support/users/torvad/)
 * (@torvad)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/problems-with-preview/#post-1664867)
 * 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.
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/problems-with-preview/#post-1664868)
 * `$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](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](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](https://wordpress.org/support/users/torvad/)
 * (@torvad)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/problems-with-preview/#post-1664869)
 * 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.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 13 replies
 * 3 participants
 * Last reply from: [torvad](https://wordpress.org/support/users/torvad/)
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/problems-with-preview/#post-1664869)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
