Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've encountered a strange error while developing a custom theme.

After finishing editing the template for a custom post type single view, I passed onto working at the template files for pages and I ealized that Wordpress was actually pointing to index.php template file rather than page.php in my theme for generating the page appearance.

I tried to change settings for website home and blog home in "reading" settings. I tried to refresh permalinks structure (normally I'm using %postname%). I also tried reverting to standard /?=post_id structure. In that case works fine... but anything with %postname% won't work.

I disabled plugins, but nothing changes. It simply refuses to work with pretty permalinks. Actually permalinks work fine for my custom post type and it won't throw 404 errors. But for every single page and post will try to fetch index.php rather than single.php and page.php (or subsequent templates for pages). I checked the configuration for my custom post type... but there's no possible conflict with pages (the url rewrite is totally different than any standard wordpress string).

I checked my .htaccess which is pretty standard as in most of my installations:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

UPDATE

I decided to throw everything away, being a test development site and started over on a clean install. Dumped the whole DB, trashed the installation files. Clean install and enabled wp_debug=true. At the beginning I noticed an error from the Dashboard:

ERROR: The themes directory is either empty or doesn’t exist. Please check your installation.

I think this is because I renamed the wp-content folder to "content"

I've done this before on other installations with this code (of course "mydomain" is my actual domain in my wpconfig...)

define('WP_CONTENT_FOLDERNAME', 'content' );
define('WP_CONTENT_DIR', ABSPATH . WP_CONTENT_FOLDERNAME );
define('WP_CONTENT_URL', 'http://mydomain.com/' . WP_CONTENT_FOLDERNAME );
define('WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
define('WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' );

After double checking and reloading the page somehow the error string disappeared. I was able to install the theme correctly (therefore Wordpress must have been aware of its location folder...)

However, the URL permalinks problem persists (wants to fetch index.php instead of page.php template for pages or single.php for posts ). This is driving me insane since it's a clean new installation.

UPDATE 2

now I'm testing with TwentyEleven/Ten and it's still throwing the same error... so I must exclude plugins and my custom theme... this has probably to do with my server config, htaccess or wpconfig probably... but I really wonder... because this is running on the same server where I have half dozen of wordpress sites configured in a similar way

UPDATE 3

after changing and updating the wp-config.php file several times I got it working at times... but for some reason it keeps breaking again... single blog posts and pages get redirected to index.php (blog home) or page template holding the blog home (if set in "reading" settings from wordpress admin). Custom post types, archives and bbpress forum pages (individual posts and archives), taxonomies... they all work fine. It's just pages and posts. I double checked the php configuration and server variables, it all appears normal

share|improve this question
add comment

4 Answers

First of all, enable WP_DEBUG in wp-config.php.

Maybe you're changing the default query. Are you running query_posts somewhere? Take a look at the global $wp_query object. If so, you might want to try WP_Query class or running wp_reset_query() instead.

share|improve this answer
    
I gave a look on wp_query when loading a page... it's like I supposed it was, it's looping as if it were the index.php (blog home), regardless of reading settings in wp and the fact it's a page (ie address bar in browser shows mydomain.com/page but in fact it's fetching the blog index and loading all posts... ) - I'm not running query_posts or querying post in any way in the header or the footer –  Fulvio Aug 3 '12 at 14:46
add comment

I think your settings in the WP-config can still be wrong - it could be your ABSPATH is returning the wrong value.

The lines you need to check and change are --- (I've taken this from Mark Jaquith skeleton local WordPress install)

// Custom Content Directory
define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/content' );
define( 'WP_CONTENT_URL', 'http://' . $_SERVER['HTTP_HOST'] . '/content' );
share|improve this answer
    
oh that was it! this was driving me crazy... I'm surprised that in this installation my usual constants didn't work - I've replaced mine with yours and flushed the permalinks now appears to be working... thanks a lot! –  Fulvio Aug 3 '12 at 16:24
    
glad to know it worked for you ... ABSPATH problems would indicate that the Apache confg.d or your vhost are not right. –  Damien Aug 3 '12 at 16:26
    
no unfortunately doesn't work anymore... at the beginning it appeared as fixed... I started editing content and uploading stuff... the problem occurred again. I don't know what trigged it again. I flushed again permalinks. –  Fulvio Aug 3 '12 at 17:02
1  
create a file on your server called test.php and just add this one line to the file <?php phpinfo(); ?> then browse to the file on your server and you can check the values for things like HTTP_HOST .. you might need to use SERVER_NAME or SERVER_ADR instead. –  Damien Aug 3 '12 at 17:26
    
thanks - HTTP_HOST and SERVER_NAME are the same 'mydomain.com' (without quotes and no http or slash), which is the correct domain, SERVER_ADR is not present - just before your comment I managed to fix it once again, but again after editing some content at some point misbehaves again and starts pointing pages to index.php (or blog home template page) in my theme - if I disable the blog home template it will redirect to index.php in my template –  Fulvio Aug 3 '12 at 18:07
show 3 more comments
up vote 2 down vote accepted

I'm going to answer my own question for the sake of people who might run in the same issue as me

in my setup I had a plugin handling taxonomies; one of these had the rewrite slug set to "year" - well, it turns out this conflicts probably with date based archives (?) and caused my posts and pages not loading but rather redirecting the user to the blog home - evidently there was some issue in Wordpress templating hierarchy; I haven't investigated further

I didn't catch the error quickly because I didn't flush permalinks properly while deactivating plugins - also for some reason the error appeared randomly (sometimes my permalinks DID work despite the taxonomy rewrite was still set)

I ended up by renaming the slug into "period", then deleting the .htaccess, recreating it, and creating/flushing permalinks from Wordpress permalinks page

that seems to have fixed it once and for all

so... if you happen to be in a similar situation, check check check everything that is altering the permalink structure in some manner, even custom post types and taxonomies, think about the slug you're using and if it may conflict with something else even not obvious

cheers

share|improve this answer
    
Thanks so much, this was driving me crazy!!! I too have a custom post type slug set to "year" and I lost a day trying to figure out what was wrong! –  Gabriela Mar 26 at 8:28
    
This is also available for "register_taxonomy" $taxonomy argument! –  Gabriela Mar 26 at 8:36
    
I can't upvote this hard enough. What a mess i was in. –  Shawn Wernig Apr 9 at 18:45
add comment

I faced the same problem and just solved the issue after spending close to an hour figuring out the issue.

So if your CPT (custom post type) single pages are using the index.php and not the single-post_type template, make sure you're not using query_posts improperly. For me, it turned out that I forgot to call wp_reset_query on one of the sidebar pages after using query_posts.

Just go through all your pages and Ctrl+F for query_posts and manually check that each of the query_posts call is closed by a wp_reset_query call after that.

share|improve this answer
    
Not to be persnickety - congrats on solving your immediate issue - but allow me to give you a hint: You are speaking of "using query_posts improperly". You could go a step further and put it this way "using query_posts is improper in the first place". Consider the WP_Query class, the get_posts function or the pre_get_posts filter instead. Reading this question and Rarsts answer might be worth your time. –  Johannes Pille Apr 22 '13 at 9:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.