{"id":4931,"date":"2020-05-10T13:57:54","date_gmt":"2020-05-10T13:57:54","guid":{"rendered":"http:\/\/wiki.davelevy.info\/?p=4931"},"modified":"2024-09-04T19:15:14","modified_gmt":"2024-09-04T19:15:14","slug":"wordpress-tags-maintenance","status":"publish","type":"post","link":"https:\/\/davelevy.info\/wiki\/wordpress-tags-maintenance\/","title":{"rendered":"WordPress Tags, maintenance"},"content":{"rendered":"\n<p>I have some notes on the wordpress schema; I am trying to tidy up my tag list on my blog, there&#8217;s a shed load of tags which only have one entry in the database, there are some spelling mistakes and some inconsistency in the use of spaces and plurals. But I might leave those with only one use on the blog\/wiki for the search engines. There are 56 which have become orphans.&nbsp; I have documented the image credit at the bottom of the article. Here are my notes &#8230;<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>This code lists tags in use and their joined posts.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>select t.term_id, t.name, r.object_id, p.post_title \nfrom xx_terms t, xx_term_taxonomy tt, xx_term_relationships r , xx_posts p \nwhere t.term_id = tt.term_id\nand   tt.term_taxonomy_id = r.term_taxonomy_id\nand   r.object_id = p.ID\nand   post_type = \"post\"\nand   tt.taxonomy = \"post_tag\"\norder by t.term_id asc\n\n\nSpelling mistakes where there is no good tag in the tag list can be corrected as follows<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">#\n# This works for spelling mistakes where there is no correct alternative\n#\nupdate xx_terms t\nset t.name = \"new tag value\"\nwhere   t.term_id = \"XXX\" OR t.term_id = \"XXX\"\n;\n<\/pre>\n\n\n\n<p>I used OR not IN because I only had two. (This shouldn&#8217;t wotk because it leaves two links where there should only be one.)<\/p>\n\n\n\n<p>I need some code to discover unused tags and to merge two (or more tags into one that exists).<\/p>\n\n\n\n<p>The active links are held in xx_term_relationships table. The tag foreign key is held in the term_taxonomy_id so,<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">select * from xx_term_relationships \nwhere term_taxonomy_id in ('830','831','832')\n<\/pre>\n\n\n\n<p>pulls a view of the active tag links.<\/p>\n\n\n\n<p>So<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">update xx_term_relationships\nset term_taxonomy_id = 'new value'\nwhere term_taxonomy_id in ( 'value 1','value 2')\n<\/pre>\n\n\n\n<p>should make unwanted links repoint at new values.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">select term_id, name from xx_terms\nwhere term_id not in (\n        select term_taxonomy_id\n    from xx_term_relationships)<\/pre>\n\n\n\n<p>should list those tags no longer connected.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>I need some code to merge which is directional i.e. each term has an ID and thus we need to merge a bad link into a good one, and delete the bad one.<\/p>\n\n\n\n<p>I had another look at this in Aug 2024, and wrote this, <\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Find the old links<\/li>\n\n\n\n<li>Find the new link row key, it may be necessary to make a new link row<\/li>\n\n\n\n<li>Associate the article row with the new link<\/li>\n\n\n\n<li>delete the old link when empty<\/li>\n<\/ol>\n\n\n\n<p>The code snips above are useful for solving circumstances where one wants to remove a link, or correct spelling. <\/p>\n\n\n\n<p>This might also need to be applied to categories too. <\/p>\n\n\n\n<p>The <strong>featured image<\/strong> is taken from <a href=\"https:\/\/imagefix.co.uk\/tag\/outsource-wordpress-maintenance\/\">this page<\/a>, by Imagefix, I have resized and cropped it, and stored and processed it for the usual reasons, of addressability, performance and longevity.<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>I have some notes on the wordpress schema; I am trying to tidy up my tag list on my blog, there&#8217;s a shed load of tags which only have one entry in the database, there are some spelling mistakes and some inconsistency in the use of spaces and plurals. But I might leave those with&#8230;<\/p>\n","protected":false},"author":1,"featured_media":4933,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","_share_on_mastodon":"0"},"categories":[3,584],"tags":[1035,911,28],"class_list":["post-4931","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology","category-wordpress-technology","tag-sql","tag-technology","tag-wordpress"],"share_on_mastodon":{"url":"","error":""},"jetpack_featured_media_url":"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2020\/05\/wp-maintenance-w650.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts\/4931","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/comments?post=4931"}],"version-history":[{"count":2,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts\/4931\/revisions"}],"predecessor-version":[{"id":11372,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts\/4931\/revisions\/11372"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/media\/4933"}],"wp:attachment":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/media?parent=4931"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/categories?post=4931"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/tags?post=4931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}