• Resolved mintydog

    (@mintydog)


    I have a site that has been functioning properly in WP 2.3.x through 2.5.x. Now it’s on 2.6.2 and I’ve noticed that the is_front_page() function appears to be broken when using a custom query. I can test is_front_page() one line before the custom query and it tells me I am on the front page. One line after I run the custom query (display the Post Titles for the 5 most recent posts) is_front_page() tells me that I am no longer on the front page.

    I’m reasonably certain this is a bug, but I don’t want to open a ticket until I’ve had a chance for someone who has found a way around this to give me their solution.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    It’s not a bug. You’re using “query_posts” and that overrides the main query, changing what “page” you’re on, for all intents and purposes. Really, query_posts should only be used to modify the main query in some minor way, not to create an entirely new query by itself.

    For secondary queries, it’s better to create separate WP_Query objects to avoid this problem.

    Example of using a separate query:

    $myquery = new WP_Query('showposts=5');
    while ($myquery->have_posts()) : $myquery->the_post();
    the_title();
    endwhile;

    Thread Starter mintydog

    (@mintydog)

    Yup, you’re right. I just wish the Codex explained it like you did. Unfortunately there’s so much contradicting info in the Codex that when you find code in there that works, you use it.

    One of these days the Great Codex God will swoop down and update/delete all the conflicting content and we’ll all be happy!

    Thanks for the info, my page works fine now.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Static Home page with custom loop, is_front_page() breaks’ is closed to new replies.