Reputation: 3563
I struggle with something which to me seems like a logic flaw from Wordpress but whether or not it is, I need a solution. I had to modify my current setup and change almost all queries to include two post types instead of only one.
Now my query works fine, but a lot of functionality lacks because is_home() returns 1 instead of 0 on my archive page. According to its documentation, the function should only be 1 on my blogs page
* If a static page is set for the front page of the site, this function will return true only
* on the page you set as the "Posts page".
As a matter of fact, it returns true
although I am in a different archive than my 'Posts page' (which is Blog). If the query of that archive just holds one post_type, is_home()
returns 0. If I add another post type to the query (which is necessary for me) is_home()
returns true
.
The problem is within the query.php
file in the Wordpress core. is_home()
returns true if, among others, is_archive
within the query object is false
. But is_archive
in my case should be true (which it is not). is_archive
would be true if is_post_type_archive
is true (which it is not).
And thats where the problem lays:
is_post_type_archive
is only set to true by Wordpress if
1) post_type is not an array, and
2) the post_type objects value for has_archive
from the query is true
Both conditions don't apply for me since 1) post_type is an array, and therefore I expect 2) there is not one post type object for an array of post types and therefore has_archive cannot be true.
Long story short: I have an archive page with posts from different post_types and it does work, but these items are not my blog page and therefore, according to the docs, is_home should still be false.
Two questions: 1) is this expected behavior of is_home()? and 2) is there another function that could substitue the function and would work with my multiple-post-type-query? (if not, any suggestions on how to achieve that?)
Thanks in advance for your ideas.
Upvotes: 1
Views: 719
Reputation: 3563
For the record (if anyone stumbles upon this thread with a similar issue): I worked around it by checking for get_post_type() == 'post'
instead of is_home()
- still not satisfying. The docs say is_home() would result in true only on the Posts page and it clearly does not.
Upvotes: 0