#7533 closed defect (bug) (wontfix)
is_page() Returns false Always In Search Results
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | high | Milestone: | |
| Component: | Template | Version: | 2.6.1 |
| Severity: | trivial | Keywords: | is_home, home, dev-feedback |
| Cc: |
Description
In the Default Theme search.php, if you do a
<?php var_dump(is_page()); ?>
after
<?php while (have_posts()) : the_post(); ?>
It always returns false even the results return is a page and not a post.
Change History (15)
comment:2
GamerZ
— 5 years ago
Yeap, I posted this issue because one of my users inserted the code of my WP-Print and WP-Email into the search.php and when the results is a page instead of a post, the plugin will return a 404 upon clicking the email/print link as is_page() returns false.
Search results may consist of both posts and pages and there is not way to tell them apart at the moment I guess.
comment:3
technosailor
— 5 years ago
Search is not a page or a post. If anything, it's an archive. Search results might include pages. They might include *all* pages in the result. But it is still is_search(), not is_page().
Am I missing something here?
comment:4
GamerZ
— 5 years ago
Search results might include pages which is right, but within the search.php WP loop, how do u tell apart a page from a post? is_search() will definitely return true as it is a search page.
comment:5
technosailor
— 5 years ago
That's what $wp_query->post_type is for :)
comment:6
GamerZ
— 5 years ago
Yea, I also thought of that, but would it be easier to standardize is_page() to return true as long as it is a page regardless of which page this function is being called?
comment:7
technosailor
— 5 years ago
- Keywords dev-feedback added
Disagree, but let's get dev-feedback :)
comment:8
follow-up:
↓ 9
GamerZ
— 5 years ago
But there is no harm in making is_page() return true in the search results.
comment:9
in reply to:
↑ 8
ShaneF
— 5 years ago
Replying to GamerZ:
But there is no harm in making is_page() return true in the search results.
Agree.
comment:10
Otto42
— 5 years ago
Disagree. It's a search archive. Not a page and not a post. Those is_whatever tags refer to where you are at in the Template Hierarchy (unless you futzed with the query manually). Making them behave differently in the Loop vs. out of the Loop is a Bad Idea(tm).
comment:11
follow-up:
↓ 12
GamerZ
— 5 years ago
It is a search archive and hence both pages and posts are searched and then the information is processed within the loop. Both pages and posts are displayed within the archive and at the moment there is no way to tell apart from them.
comment:12
in reply to:
↑ 11
;
follow-up:
↓ 13
Otto42
— 5 years ago
Replying to GamerZ:
It is a search archive and hence both pages and posts are searched and then the information is processed within the loop. Both pages and posts are displayed within the archive and at the moment there is no way to tell apart from them.
if (get_post_type($post) == 'page') ...
I can see adding a get_the_post_type() function, because we're in the Loop, but not changing the nature of the is_page value.
comment:13
in reply to:
↑ 12
GamerZ
— 5 years ago
Replying to Otto42:
if (get_post_type($post) == 'page') ...
I can see adding a get_the_post_type() function, because we're in the Loop, but not changing the nature of the is_page value.
That is another workaround I thought of as well. I think I beginning to get what you mean by "but not changing the nature of the is_page value"
comment:14
azaozz
— 5 years ago
- Resolution set to wontfix
- Status changed from new to closed
The is_page() returns true only when a single page is displayed (as it should be). When need to determine the post type of each search result, get_post_type($post) can be used in the loop, as Otto42 points out.
comment:15
thee17
— 5 years ago
- Milestone 2.7 deleted
technically, Its not a "page" either really.. Hostorically its closer to posts rather than pages.
there's another conditional, is_search() i believe which can be used for those situations.
(When i think of a "page" i think of a User defined page, When i think of a "post" i think of a Single view, When i think of a "search" i'm thinking of the Search page & search template)