thingsym / custom-post-type-widgets

WordPress plugin 'Custom Post Type Widgets' adds default custom post type widgets.
https://wordpress.org/plugins/custom-post-type-widgets/
GNU General Public License v2.0
27 stars 14 forks source link

Archive widget uses wrong slug if has_archive is defined as a string #19

Open ykyu opened 3 years ago

ykyu commented 3 years ago

Currently the plugin uses the CPT's post type slug, but when defining the CPT, it is possible to assign a specific archive slug.

E.g. for post type "movie" a single movie would be at site.com/movie/the-lion-king, while a movie index or archive view might be at site.com/movielist/2020/12. The plugin currently would use site.com/movie/2020/12, which would 404.

The fix is simple. In /inc/widget-custom-post-type-archive.php

Find: $archive_name = ! empty( $type_obj->rewrite['slug'] ) ? $type_obj->rewrite['slug'] : $posttype;

Replace: $archive_name = is_string($type_obj->has_archive) ? $type_obj->has_archive : (! empty( $type_obj->rewrite['slug'] ) ? $type_obj->rewrite['slug'] : $posttype;);

WillPresley commented 2 years ago

Just coming in to say thanks for this, and also @ykyu you have an extra semicolon as the 3rd-to-last character.