• Resolved sethadam1

    (@sethadam1)


    I’ve got a tough one.

    My WordPress install just starting returning a 404 for all “page” post_types. It works for posts, including custom post types, categories, tags, and date ranges. The only problem is with pages.

    I use Apache configs, and verified they were accurate. So then I switched to .htaccess and verified that too. I’ve changed my theme to the default. I’ve rebuilt my permalink structure. The pages are *definitely* there in the database. But I still get “page not found” errors. Anyone have any ideas where to check?

    Follow up: pages with custom templates don’t work. restarting apache and mysql don’t work, nothing in the PHP error log.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter sethadam1

    (@sethadam1)

    Oddly enough, it was a plugin… one that *I* wrote for the site… that worked for the last week without an issue. I’m not sure what could cause it to suddenly break, but I’ll update if/when I figure it out.

    Thread Starter sethadam1

    (@sethadam1)

    I tracked it down to this line:

    add_action('pre_get_posts','myfunc');

    Commenting that out worked. With that line in my plugin, no “page” post_type will load – just “page” types, no others are affected. I mean… that’s weird, right?

    Thread Starter sethadam1

    (@sethadam1)

    Stupid mistake of the day leaving it up for anyone else goofy enough to make this mistake:

    All pages broken:

    add_action('pre_get_posts','myfunc');
    function myfunc($query) {
    	if ( $query->is_main_query() ) {
    		if(!is_admin()) { $query->set('post_type', array( 'post', 'podcast' ) ); }
    	}
    }

    All pages magically UNbroken:

    add_action('pre_get_posts','myfunc');
    function myfunc($query) {
    	if ( $query->is_main_query() ) {
    		if(!is_admin()) { $query->set('post_type', array( 'page', 'post', 'podcast' ) ); }
    	}
    }

    When you load a page, it fires the pre_get_posts action, which is odd, because you’d expect fetching a single post not to fire pre_get_posts, but it does.

    So… mystery solved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Pages 404'ing, but not posts or custom post types’ is closed to new replies.