WordPress.org

Ready to get started?Download WordPress

Forums

CPT-onomies: Using Custom Post Types as Taxonomies
problem when duplicate product in woocommerce (5 posts)

  1. chknwng
    Member
    Posted 1 year ago #

    Hi,

    Thanks for your plugin and thanks for your answers :)

    And by advance, sorry for my weird/funny english. I don't write it or speak it very often.

    So, I have a cptonomy my_author I associate with several post types, like blog posts, videos, links and products from woocommerce.

    There is my 3 use cases:
    1/ I gather all these informations in the single-my_author template with custom queries.
    2/ I filter post type archives with my_author (?taxonomy=my_author&term=john-doe)
    3/ I don't use cpt_onomy_archive for now, but it's nice

    There is a problem with woocommerce when I duplicate a product in admin panel.

    All the my_author terms that are associated with the product are added to the wp_terms table in the database, with the taxonomy my_author in wp_term_taxonomy table. Before that, there is no taxonomy that equals a post_type.

    So, It changes the SQL query on all the 3 use cases.
    It looks for posts that satisfy your "wp_postmeta.meta_key / _custom_post_type_onomies_relationship" condition (like before).
    But it also add another statement based on "wp_term_relationships.term_taxonomy" with the fresh terms it just created.

    Of course, only the new (duplicate) product satisfy these 2 conditions, and after that, only post that I duplicate can satisfy them (or I have to associate manually my posts with those taxnomies).

    So it breaks everything.

    To solve this, you just have to remove these "wp" taxonomies from database, and behaviour is back to normal.

    I add a silly filter to prevent that bug for now, it seems to work but I don't know if it fits or not the plugin functioning ^^.

    add_filter('pre_insert_term', function() {
            if (in_array($taxonomy, get_post_types()))
                return new WP_Error();
        }, 10, 2);

    Alright, thank you :)

    http://wordpress.org/plugins/cpt-onomies/

  2. chknwng
    Member
    Posted 1 year ago #

    Sorry, the code was not correct

    add_filter('pre_insert_term', function($term, $taxonomy) {
            if (in_array($taxonomy, get_post_types()))
                return new WP_Error();
            return $term;
        }, 10, 2);

    I didn't find the time yet to dig into thi bug

  3. maricel0422
    Member
    Posted 1 year ago #

    Hi cjlmwmg,

    I am having a similar problem. Can you provide the name of the file you modified? Txs!

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    @maricel0422: If you require assistance then, as per the Forum Welcome, please post your own topic.

    This 4 month old topic references an old version of WordPress.

  5. chknwng
    Member
    Posted 1 year ago #

    Hi,

    you can add this code in your functions.php or any other php file I think.
    I put mine in a file inside a personal plugin.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.