Support » Fixing WordPress » Upgrade broke conditional tags

  • Resolved thorwik


    Long overdue, we finally decided to take the plunge and upgrade our WordPress 2.9.1 website with the WP e-Commerce plugin to the latest version. Unfortunately the upgrade for some reason broke several conditional tags in our selfmade dynamic theme.

    if (is_page(107) || $post->post_parent == '107') get_sidebar('shop');

    This code no longer identified the subpages to 107 and the only fix I could find was to add all the separate subpage ids in is_page tags, thankfully there are only three subpages there.

    Even with the subpages’ ids included, if you navigate to a product page (i.e. ) the shop sidebar condition is once again not met although it worked fine before the upgrade.

    products-page is the page with id 107, aloittelijalle is a product category and discover-the-classics-vol-3-the-concerto the product.

    Another broken tag is the one that checks if you’re on an article page or not:

    if ( is_home() || is_archive() || is_page(81) || $post->post_parent == '81')

    This one still works on the archive pages when you select a certain month but if you head to the main archive page (id 81) that shows the most recent articles it no longer meets this condition for some strange reason.

    The strangest thing of all is a really big bug that involves both of the previous ones. When you from the WP e-Commerce category widget click on a category (i.e. or depending on the permalink style), instead of getting to the list products in that category you get transported to the article page (id 81) and when you get there this way the above condition is met and the code recognizes it as the article page.

    When testing further I found that when I remove the conditional tags that try to identify the article page the product category page gets loaded and not the article page, but the conditional tags that load the sidebar and page header still identify it as an article page. It looked to me like the issue could be some sort of conflict with the page id numbers so I tried making a brand new article page with a new id and changed all article-related conditional tags to look for that page instead, but the issue remained the same.

    Now you’d think the WP e-Commerce plugin would be behind all the problems, but even if I disable the plugin the conditional tags that are supposed to identify article pages still won’t work. It’s a very strange bug and I would appreciate any advice I could get towards fixing it. I’d give you the direct links to the site, but it’s currently closed to the public due to the issues caused by the upgrade. We naturally hope that we’d be able to put our site back online soon. Thank you for your time and interest!

Viewing 11 replies - 1 through 11 (of 11 total)
  • esmi


    Forum Moderator

    My guess is that there is an issue with the Loop in those template files so that the is_page logic fails.

    Would you care to clarify a bit? What could be causing it and what could be done to fix it? Do you need to see more of the code? The failing logic is not consistent, sometimes a is_page condition fails, sometimes a post_parent condition and sometimes everything works. It’s always the same ones that fail though.



    Forum Moderator

    If the WordPress query has been customised in any way (such as using query_posts), conditionals such as is_page() may no longer work as you might expect them to.

    I’m pretty sure I’ve only used WordPress’ own functions and codex and not touched the database or made any own queries.



    Forum Moderator

    query_posts is a WordPress function.

    Oops, my bad! I have indeed used the function once to exclude a certain category from the main article page:

    query_posts($query_string . '&cat=-18');

    If I remove it the product categories no longer redirect to the article page (yay!) but the single product page still doesn’t meet the condition for the shop sidebar and then I need to find another way to exclude category 18 from the article page.

    The broken parent_page condition was also caused by that one line of code. You’re very good! If I can just find a way to exclude category 18 from the article page that doesn’t break the site I’ll be happy. The shop sidebar not showing on single product pages is a relatively small issue compared to the others and I may be able to come up with some kind of workaround to it.



    Forum Moderator

    I don’t think this is an issue that is going to be solved easily via a forum. If conditionals stop working, it’s because the logic within the template for file is faulty. I’d suggest that you try dumping the $wp_query and $post variables to the screen at appropriate points so you can see exactly what data is coming in and what page/post you are actually “on”.

    So you’re saying the query_posts restriction should work but there is something else in the code that makes it break the conditionals? Can you think of anything in particular that has changed between 2.9.1 and 3.1.1 that could be behind it? I’ll go dump the variables as you advised and hope they’ll provide some more details about the problem.



    Forum Moderator

    query_posts does work but it can also completely over-write the default query – which means that the page name or id may no longer apply. This in turn can cause your is_page to fail because the query no longer has any relationship with that page.

    See for a more detailed breakdown of the issues and how to avoid them.

    Nothing has really changed since 2.9 in terms of the functionality of either query_posts or is_page but it’s entirely possible that some bugs were corrected and that it was the existence of these bugs that allowed your pages to work as you wanted previously.

    Does that all make some kind of sense now?

    Yes, thank you for your help.

    I quickly saw that I had left out the reset query at the end of the loop so I added it:


    I also discovered that the problem with the article page is not that the conditionals aren’t met but that the query_posts restriction doesn’t work on the main article page for some reason while it does work on the archive pages and home page.

    Either way, the query_posts doesn’t seem to break the shop page anymore so I’m once again a bit closer to my goal and just need to figure out why the query_posts category restriction doesn’t work on the article page. No kind of query_posts seem to affect that page anymore for some reason. Perhaps I could try add a bit of code that manually loads the articles when the is_page(81) conditional is met and remove the article page assignment in WordPress’ settings, or would that just be going around the bug instead of actually getting rid of it?

    I found it!

    The correct way to restrict the category universally in 3.1.1 is:

    query_posts( 'cat=-18' );

    without the query_string and &.

    Thanks again for pointing me in the right direction. This issue has been resolved. 🙂

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Upgrade broke conditional tags’ is closed to new replies.