0

So, I was doing some SEO work for my company's website. The website is an online e-shop, where you can learn about their products and make an order. They also got a blog. So far so good. The set up is Wordpress obviously along with WooCommerce.

What I see is that there is an option to add a product and another option to add a blog article.

When I was doing my SEO, I managed the product tags. I was happy with how I made things work for products.

Here is the deal: If you want to add tags for a post, you can NOT access tags for products. All right I get it, it is smart that way. But I don't like the idea of just copy-paste the whole stuff from one tag group to another manually.

So, is there a way to duplicate the product tags to blog article tags, or am I forced to do it manually?

I mean some products share a tag, let's say an ingredient. It would also be helpful and nice to got this tag on blog posts about the ingredient, the product or both.

Edit: Just to clarify, I don't wanna have the product tags shared with blog post tags. I want the product tags when clicked to show only the products sharing that tag. But when it comes to blog posts, it would be nice to have the same tags (same text) that can show all the blog postst sharing them. Products can be linked in blog text hyperlings I suppose.

7
  • Could you add some examples to make it more clear? It would be helpful, I guess. Feb 11, 2019 at 10:56
  • Technically I want to transfer the product tags (all my entries) to the blog post tag entries. Simple as that.
    – George Eco
    Feb 11, 2019 at 10:58
  • So you want to duplicate terms from Product tags to blog tags. And how about blog tags? Should they be copied for Product tags? Feb 11, 2019 at 11:02
  • No. I just want the product tags entered in the blog, not the other way around.
    – George Eco
    Feb 11, 2019 at 11:03
  • I imagine that there might be a way. I mean, just with little fantasy, I can imagine an xml tag exporter-importer. Not sure if something like that exists though, cause it must support the woocommerce Product entries AND the blog entries. But that would be a solution. Just an example of what I am looking for.
    – George Eco
    Feb 11, 2019 at 11:13

2 Answers 2

1

OK, so you can use created_term hook to make the product tags copy themselves automatically to post tags.

function ( $term_id, $tt_id, $taxonomy ) {
    if ( 'product_tag' == $taxonomy ) {
        $term = get_term( $term_id, $taxonomy );
        wp_insert_term( $term->name, 'post_tag' );
    }
}
add_action( 'created_term', 'copy_product_tags_for_blog', 10, 3 );

And you’ll have to run a simple loop for tags that are already in DB.

2
  • It's hard for me to follow, because I need to understand what a hook is first. You are probably answer to my question. Assuming that I know mysql and php, and I got access to phpmyadmin, is there a way to do this with an sql query directly? That would be even more simple. Do you know where product tags and post tags respectively belong? If I know the tables, I can do the magic I suppose.
    – George Eco
    Feb 11, 2019 at 11:34
  • Ok searched for hooks, I understand now. But I would prefer to alter directly the database of wordpress if possible. If you don't know where to find the tags, nevermind, I will try to find out myself, you helped me very much guiding me to the right direction and I learned something new today. So thank you anyway. Answer accepted.
    – George Eco
    Feb 11, 2019 at 11:42
0

Yes, you can register the WooCommerce product tags (taxonomy) on your posts. Normally this would be done when you register the post type, but you can use register_taxonomy_for_object_type to register the product_tag from WooCommerce against your normal posts:

register_taxonomy_for_object_type( 'product_tag', 'post');

You can also change the labels for this, as it will display Tags twice under Posts:

function add_product_tags_to_post() {
    global $wp_taxonomies;

    register_taxonomy_for_object_type( 'product_tag', 'post');

    $labels = &$wp_taxonomies['product_tag']->labels;
    $labels->name = 'Product Tags';
    $labels->singular_name = 'Product Tag';
    $labels->add_new = 'Add Product Tag';
    $labels->add_new_item = 'Add Product Tag';
    $labels->edit_item = 'Edit Product Tag';
    $labels->new_item = 'Product Tag';
    $labels->view_item = 'View Product Tag';
    $labels->search_items = 'Search Product Tags';
    $labels->not_found = 'No Product Tags found';
    $labels->not_found_in_trash = 'No Product Tags found in Trash';
    $labels->all_items = 'All Product Tags';
    $labels->menu_name = 'Product Tags';
    $labels->name_admin_bar = 'Product Tag';
}

add_action('init', 'add_product_tags_to_post');
2
  • 1
    I’m almost sure that it’s not what the question is about... You’re registering all taxonomy for posts, but it will break the shop functionality (you’ll be showing blog posts in the shop or won’t show this taxonomy for blog) - so I don’t think it will help with SEO ;) Feb 11, 2019 at 10:59
  • 1
    Technically I want to transfer the product tags (all my entries) to the blog post tag entries. I just wanna use same tags on blog posts, that's all. Is there an easy way to transfer them? That is what I ask.
    – George Eco
    Feb 11, 2019 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.