2

I tried the following phpMyAdmin query to merge my category 112747 into my category 112748:

UPDATE `wp_term_relationships`
SET `term_taxonomy_id` = 112747
WHERE `term_taxonomy_id` = 112748;

It did not work. What errors does the query contain?

wordpress 3.8.2

phpMyAdmin 4.18

MySQL 5.5.34-cll-lve

A wordpress website of mine has nearly 300,000 posts, with most categories containing, at least, 5,000 posts. I want, among other things, to merge many of the categories, in an attempt to improve website speed and performance.

I have tried using several different plugins to merge categories from within the wordpress dashboard, but it seems my ability to successfully use the plugins is being adversely affected by various mysql, cpu, and php automatic kill/limiting features of the shared hosting environment(cloudlinux) where my website is located; in other words, the tasks get "killed" before they complete, sometimes, "crashing" the entire website.

I am aware that deleting a category, using the wordpress dashboard, moves that category's posts to the default category; so, I have even tried changing the default category to a category into which I want to merge "another" category and deleted the "another" category, but, apparently, the task still, eventually, gets "killed" or "times out".

What, typically, has been occurring, when I attempt to merge categories, from the wordpress dashboard, using a plugin or by deleting a category, is that the "merge" only partially completes. For example, maybe 30 or 400 posts from a category do get merged, but, then, the task gets "killed" or "times out", sometimes generating an error in the wordpress dashboard, sometimes "crashing" the website, and sometimes doing both.

Typically, if all posts do not get merged, I am able to, incrementally, repeat the task, using the wordpress dashboard, but this may take repeating the task many times, to get a category of 15,000 posts merged into another category. Moreover, if the website "crashes" on a particular "repeat", then, I must wait for the website to "recover" from the crash.

So, considering the aforementioned problems I have encountered, while attempting to merge categories from within the wordpress dashboard, I felt it would be much more efficient and simple to just use phpMyAdmin to merge categories, etcetera.

However, it seems as if the wordpress database structure has become much more complex. I thought I was able to use phpMyAdmin to do this kind of thing 5 years ago, or so, with much greater ease and simplicity.

In this particular instance, I confirm "term taxonomy id's", etc., multiple times, before attempting the actual query; in order to avoid needless mistakes. Some of my forum posts, however, may show incorrect term taxonomy ids, because, in this particular instance, of the manner in which I have copy/pasted from a text file that lists all my failed attempts. Again, when I am actually attempting a query, however, I check such things as "term taxonomy id's" multiple times, before proceeding with the query.

  • Can you be more specific? I can't imaging a situation when you need to do what you code is saying. Is it possible that what you want to do is migrate posts from one category to another and after that delete the empty category? – cybmeta Apr 20 '14 at 21:00
  • Assuming you double checked the term taxonomy ids, there is a possible error: if some posts associated with the term having term_taxonomy_id 112748 are already also associated with the term having term_taxonomy_id 112747 your query attempt to create a duplicate row in wp_term_relationships table and that's not possible, because there is a PRIMARY index on that table on the 2 columns object_id, term_taxonomy_id. You should use PHP to have control on the query because even technically possible a complex query for your scope will be very hard to write and it will very easy fail. – gmazzap Apr 21 '14 at 0:20
  • Please clarify how this question is specific to WordPress, rather than merely happening in the context of WordPress. You're using phpMyAdmin to manipulate data in a SQL database. – Chip Bennett Apr 22 '14 at 12:17
  • Thankyou for replying. @cybnet I edited my original question. @ G.M. I check ids multiple times, before querying. Why would some posts already be associated? Are you able to provide details(link, etc.) describing the PHP method of merging wordpress categories? – q305noonce Apr 22 '14 at 12:23
  • @ChipBennett The question basically is: "How do I merge one taxon into another taxon (alias: term)". It should be rephrased, but not closed. – kaiser Apr 25 '14 at 6:37
1

You can't simply "merge categories" you have to change the category that each post is associated with. The table WP_TERM_RELATIONSHIPS links posts with categories. You could try something like this:

UPDATE wp_term_relationships 
SET term_taxonomy_id = 
   (SELECT term_taxonomy_id FROM wp_term_taxonomy WHERE term_id = 112748)
WHERE term_taxonomy_id =
   (SELECT term_taxonomy_id FROM wp_term_taxonomy WHERE term_id = 112747)

You might also try this plugin: http://wordpress.org/plugins/batchmove/

  • My initial post in this thread includes a query I used, similar, in appearance, to what you have provided, @unifiedac, that did not succeed. The batch-move wordpress plugin is amongst those wordpress plugins, to which I have made reference in my initial post, that was adversely affected by the issues I describe in the aforementioned post. – q305noonce Apr 22 '14 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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