Support » Fixing WordPress » Can't preview posts in Wp 3.2.1

  • a_crezo

    (@a_crezo)


    Attempting to preview a post (published, public) allows preview (unnecessary, since it is published and public and easily accessible from the front end.)

    Attempting to preview a post (scheduled, public) returns a 404 Error.

    Attempting to preview a post (draft, public) returns a 404 Error.

    Attempting to preview/view a post (published, private) returns a 404 Error.

    Attempting to preview a post authored by another user (author access v. my admin access) returns “You do not have permission to preview drafts.” <— THIS IS A PROBLEM. Has anyone found a fix for this yet?

Viewing 5 replies - 1 through 5 (of 5 total)
  • MrsCassandra

    (@mrscassandra)

    Hi,

    I had a very similar problem and finally fixed it only restoring/repairing all permissions of all folders in the website.

    Fortunately my hosting provider offers a feature that does exactly this task automatically.

    Have a look if your provider has a similar feature or check permissions.

    I have the same problem but have not found a solution yet.

    The same problem still occurs on my localhost. The Super Admin can preview posts but other users, even one’s with Editor permission, still cannot preview posts.

    Tracked it down to the following code in my theme:

    add_filter( 'pre_get_posts', 'my_get_posts' );
    function my_get_posts($query) {
    
        // Alters the main query to include different post-types by default everywhere
        // Useful when you want to mash up everything into the same feed
    	if ( !is_admin() && false == $query->query_vars['suppress_filters'] ) {
            // Add your different post-types below ie. reviews, previews etc.
            $query->set('post_type', array(
                'post',
                'review'
            ));
        }
    
    	return $query;
    }

    Looking at how to fix it.

    Fixed it. Originally I took my example from http://justintadlock.com/archives/2010/02/02/showing-custom-post-types-on-your-home-blog-page but didn’t add any filtering for the category or the home page.

    Here is the updated code:

    add_filter( 'pre_get_posts', 'my_get_posts' );
    function my_get_posts($query) {
    
        // Alters the main query to include different post-types by default everywhere
        // Useful when you want to mash up everything into the same feed
    	if ( !is_admin() && false == $query->query_vars['suppress_filters'] ) {
            if (is_category() OR is_home()) {
                // Add your different post-types below ie. reviews, previews etc.
                $query->set('post_type', array( 'post', 'review' ) );
            }
        }
    
    	return $query;
    }

    @flashuk,

    Thank you for documenting your fix. I’m using custom post types extensively on a site, and we built this function right into the theme. Adding that filter for is_category() || is_home() did the trick. Now I can preview posts!

    (Using WordPress 3.3.1)

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Can't preview posts in Wp 3.2.1’ is closed to new replies.