[wp-trac] [WordPress Trac] #20647: get_post_type() returns nothing on custom post type archive pages with custom query and no results

WordPress Trac noreply at wordpress.org
Mon Jan 15 12:27:14 UTC 2018


#20647: get_post_type() returns nothing on custom post type archive pages with
custom query and no results
-------------------------------+------------------------------
 Reporter:  MikevHoenselaar    |       Owner:  MikevHoenselaar
     Type:  defect (bug)       |      Status:  closed
 Priority:  normal             |   Milestone:
Component:  Posts, Post Types  |     Version:  3.3.2
 Severity:  normal             |  Resolution:  invalid
 Keywords:  needs-patch        |     Focuses:
-------------------------------+------------------------------

Comment (by sicle):

 I know this ticket is closed, however it still shows up as the first page
 on Google when searching for 'get_post_type returns empty or nothing', so
 I thought I'd share som more general insight on get_post_type() returning
 nothing in a more general sense.

 I had some troubles with get_post_types() as well, turns out it had to do
 with permalinks caching.
 For me the fix was going to Settings->Permalinks and just hitting 'Save
 Changes', it updated the permalinks and saw my post types again.

 Worth noting, all other methods also resulted in empty results, as it
 simply couldn't query anything and as such get_post_type() is also empty.

 I actually run into empty query problems more often during theme
 development, before you try changing your code, just try to update the
 permalinks, fixes a lot of things.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/20647#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list