Forums Forums Search & Filter Pro Shared taxonomy issues

Tagged: 

Viewing 10 posts - 1 through 10 (of 15 total)
  • Anonymous
    #120488

    tl;dr Does SF Pro support shared taxonomies and if not, point me in the right direction?

    I’ve got a custom taxonomy being shared across 3 custom post types, with taxonomy term archives rewritten using add_rewrite_rule to use /cpt-base/shared-term, /cpt-base-2/shared-term, etc. These are working as expected, showing only those custom post types with the specified term. The taxonomy is registered like this and the rewrite looks like this.

    Each CPT has its own SF shortcode set to Post Type Archive (mainly to sort by post meta/date) and most importantly, Enable Filtering on Taxonomy Archives is checked so the filters work on the taxonomy term archives too. For the custom post type archives, and the first post type’s term archives, everything works great.

    Here’s the problem: when Enable Filtering on Taxonomy Archives is selected, $wp_query->query_vars['post type'] for the remaining taxonomy term archives gets set to the wrong post type, even though $wp_query->query['post type'] is the correct post type.

    Here’s a var dump of $wp_query for a term archive for the first CPT, which works fine: https://cl.ly/lXEV
    Here’s a var dump of $wp_query for a term archive for the second CPT, which shows for wp_query->query_vars['post_type'] incorrectly set to the first CPT: https://cl.ly/lWVk

    When the forms are deactivated, or the taxonomy filtering option is turned off, the correct posts show up on the archives. I’ve tried turning off AJAX, no difference.

    Side note: I can confirm that the correct form shortcodes are being added to the correct post type archive and taxonomy term archive through conditional statements. Since query_vars is not returning the correct post type, post_type_archive() and get_post_type() conditionals don’t work, so I’m using if ( 'post_type_name' == $wp_query->query['post_type'] ). Also, all posts are using archive.php.

    Last thing: I also tried using sf_edit_query_args (gist) to set the post type but it didn’t seem to work and just caused more problems.

    Hopefully I’m overlooking something easy!

    Trevor
    #120560

    Hi

    Sharing taxonomies across Post Types is discouraged. Indeed, the WordPress started a project some time ago called Term Splitting, in an attempt to bring some clarity, but, IMHO, made more of a mess of it than it already was. You are far from the first to realize that this is not the best way to organize data (it is the WordPress equivalent of a couple having a shared bank account – it can get very messy trying to figure what belongs to who).

    This post tries to explain this a bit better (you can use a plugin to switch category terms from category to any new taxonomy that you make, so it is not so hard to do). It is a really awful preachy lecture I wrote:

    https://support.searchandfilter.com/forums/topic/multiple-categories-combination/#post-55166

    Sorry about the tone, but the message is right and it links to good plugins (except taxonomy switcher I think). If I missed anything (I probably did, my apologies), follow up and nudge me.

    Anonymous
    #120651

    Thanks for the response. Regarding term splitting – I’m fairly sure that refers to term slugs shared among different taxonomies, not one taxonomy being shared among different post types which is what I’m getting at.

    Anyways, I know it’s not super common but WP core does support multiple post types sharing a single taxonomy, and there is documentation out there for how to achieve what I’ve already successfully implemented (ie, taxonomy term archives that look like /cpt-slug/shared-term-slug).

    I guess my point is that if I can get things to work on my end without the plugin, and adding the plugin causes a reproducible issue, it seems like there should be a way to resolve it so that it works as expected. And especially since I can pin the issue down to enabling one specific checkbox – Enable Taxonomy Filtering on Taxonomy Archives.

    Perhaps Ross has some insight he could share with me on this? If this is perhaps wandering towards custom code territory and beyond your normal scope of support, I’m open to suggestions for how to get this resolved. Thanks again for the guidance.

    Trevor
    #120678

    I will flag it for him to look at, but the weekend beckons.

    Anonymous
    #121656

    Following up to see if you had a chance to look at this. Thanks!

    Ross Moderator
    #121714
    This reply has been marked as private.
    Ross Moderator
    #121993
    This reply has been marked as private.
    Anonymous
    #122065
    This reply has been marked as private.
    Anonymous
    #122087
    This reply has been marked as private.
    Ross Moderator
    #122315
    This reply has been marked as private.
Viewing 10 posts - 1 through 10 (of 15 total)