Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 7 years ago

#24473 closed enhancement (duplicate)

is_home returns true for pages created with custom rewrite_rules

Reported by: lucasms's profile LucasMS Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.5.1
Component: Query Keywords:
Focuses: Cc:

Description

I have a plugin for question and answers, where the questions index and question pages are created using add_rewrte_rule . (I know I could do something similar using custom post types, but this plugin was done long before this feature).

here are my rewrites called in init hook:

add_rewrite_rule('^questions/([^/]+)/?', 'index.php?questions_category=$matches[1]', 'top');
add_rewrite_tag('%questions_category%', '([^&]+)');

The problem is, in the header of the template I use is_home() to load some custom codes, but is_home() is returning true in theses question pages.

Tthese pages are not of any wordpress type (post, page, 404, home, archives - tax, dates, categories and so on). My suggestion is to create a new is_dynamic boolean variable for this kind of pages.

Change History (6)

#1 @SergeyBiryukov
11 years ago

  • Component changed from Rewrite Rules to Query

Basically, you're adding a custom query variable:

http://mysite.com/?questions_category=...

WP_Query still considers this a home page, since is_home the default fallback if none of the other conditions are true. See the comments on #18114.

Last edited 11 years ago by SergeyBiryukov (previous) (diff)

#2 @wonderboymusic
11 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Filter query_vars, add questions_category to it, and then use get_query_var( 'questions_category' ) in your theme to know when you're on it

#3 @LucasMS
11 years ago

wonderboymusic, that was not the problem. I know what you said, but, I have some codes in the header that should only be loaded in the home page, and I used is_home() for that. But is_home returns true when it's not the home. For me, this is a problem.

#4 @markoheijnen
11 years ago

You can still set is_home to false on the action 'pre_get_posts'. That is what I do.

#5 @SergeyBiryukov
11 years ago

  • Resolution changed from wontfix to duplicate

Duplicate of #18114.

#6 @mordauk
9 years ago

Looks like the patch on 25143 likely resolves this too.

Version 0, edited 9 years ago by mordauk (next)
Note: See TracTickets for help on using tickets.