[wp-trac] [WordPress Trac] #63091: wp_get_archives() with post_type parameter generates duplicate query parameters in URLs

WordPress Trac noreply at wordpress.org
Thu Mar 13 04:05:36 UTC 2025


#63091: wp_get_archives() with post_type parameter generates duplicate query
parameters in URLs
--------------------------+-----------------------------
 Reporter:  childsview    |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Taxonomy      |    Version:  6.7.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 When using wp_get_archives() with a custom post_type parameter, the
 function generates URLs with duplicate query parameters. For example, when
 using:

 {{{
 #!php
 wp_get_archives(array(
 'type' => 'yearly',
 'post_type' => 'magazine'
 ));
 }}}

 The generated URLs look like:
 {{{
 https://example.com/2023/?post_type=magazine?post_type=magazine
 }}}

 Instead of the expected:
 {{{
 https://example.com/2023/?post_type=magazine
 }}}

 This duplicate query parameter causes issues when trying to access these
 archive pages, as the URL is malformed with two question marks.

 == Steps to Reproduce ==

 Create a custom post type (e.g., 'magazine')

 Add several posts to this custom post type with different dates spanning
 multiple years

 Add the following code to a template file:
 {{{
 #!php
 wp_get_archives(array(
 'type' => 'yearly',
 'post_type' => 'magazine'
 ));
 }}}

 View the page and inspect the generated archive links

 == Expected Result ==

 Archive links should have a single query parameter:
 {{{
 https://example.com/2023/?post_type=magazine
 }}}

 == Actual Result ==

 Archive links have duplicate query parameters:
 {{{
 https://example.com/2023/?post_type=magazine?post_type=magazine
 }}}

 == Environment ==

 WordPress version: [Your WP version]

 Theme: [Your theme, but also tested with default theme]

 Plugins: [List plugins, or note that it happens with all plugins
 deactivated]

 Permalink structure: [Your permalink structure]

 == Workaround ==

 Currently using a filter to fix the URLs:
 {{{
 #!php
 function fix_duplicate_post_type_query($link_html) {
 return preg_replace('/?post_type=([^&]+)?post_type=\1/', '?post_type=$1',
 $link_html);
 }
 add_filter('get_archives_link', 'fix_duplicate_post_type_query');
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63091>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list