Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#47096 closed defect (bug) (worksforme)

get_post_type() in author.php return random post type

Reported by: wolly's profile wolly Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

I have created an author.php page.

I have a do_action in sidebar

When I add_action I check if it's a given post type, before adding action.

But in author.php get_post_type() return a CPT, different on different server, maybe it's the last registred.

Change History (4)

#1 @swissspidy
5 years ago

get_post_type() returns the post type of the global $post, which can be a different post depending on where exactly on your page you are calling it and depending on what kind of posts the author has written.

Not sure what else you would expect from that function on the author archive..?

#2 @wolly
5 years ago

In the sidebar I have a function that check what cpt is.

Based on that check, I add action or not.

I solved using ! is_author, but, probably is my mistake, I thought that in author php I had non CPT value.

You are sayng that it take the cpt value of the post in the loop, in this case, the first one, since the loop is of mixed post type.

If this is the expected result, it's not a bug :-)

Thanx a lot for your time

#3 @knutsp
5 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

Would guess it returns the type of the last post in the loop, when in a sidebar that is rendered after the loop.

#4 @SergeyBiryukov
5 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.