Support » Fixing WordPress » Using MySQL to Categorize and to Tag

  • oeconomist


    I’d like to use MySQL to add tags and categories to entries already in my database.

    A plugin purged all the categories and tags that were used exclusively for restricted entries. Unfortunately, I did not discover this behavior until I had made various content changes.

    Thus, I’d like to run a query to find every entry with restricted access, and put it into a category for such entries. And I’d like to run a query to associate various entries with various tags, based upon the appearances of substrings within those entries.

    After I post this request, I will be looking at the documentation for the database structure, but I am hoping that someone can provide a quick answer.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Joy


    It’s not a quick answer sort of thing. There are multiple tables to update, so it’s a complicated query. You would be better off to find a plugin, or to use the Bulk Edit feature of the Post list. You can use the search field to list the posts with certain strings, then select the ones you want with the checkboxes. Then Bulk Edit to add the category.



    Thank you for your response.

    Exactly because it isn’t a problem quickly solved, I was hoping that someone had already solved it. I wasn’t looking for someone to do a lot of new work on my behalf. And I was and am aware that my hope was and is likely to be dashed.



    I’m new to wp, MySQL, PHP but have a little SQL skill from SQLite and was perplexed that tags created by the hashtagger plugin for pages I had imported from HTML into YadaWiki pages (YadaWiki and HTML Import 2 plugins) were not appearing in Tag Cloud widget under either the Tags or Wiki Tags taxonomy (latter added by YadaWiki). I wonder if the plugin that evaporated your tags for restricted entries may have produced a similar condition.

    wp_posts.post_type is assigned ‘post’ for normal posts, ‘page’ for normal pages and ‘yada_wiki’ for …

    wp_term_taxonomy.taxonomy is assigned ‘post_tag’ for terms applying to posts (maybe pages, too) and ‘wiki_tags’ for terms applying to YadaWiki pages.

    What fell apart, in my case, was that the taxonomy ‘post_tag’ was assigned to terms applying to wiki pages. The Tag Cloud for Tags worked but does not count any of the posts of type ‘yada_wiki’ even though they had tags of taxonomy ‘post_tag’. If the wp_term_taxonomy.count=0, the tag is not displayed in the cloud. And selecting the ‘Wiki Tags’ taxonomy in the Tag Cloud resulted in no tags in the cloud because none of the posts of type ‘yada_wiki’ had tags of taxonomy ‘wiki_tags’.

    I was able to cobble together a SQL script that changed the wp_term_taxonomy.taxonomy to ‘wiki_tags’ for those terms that applied to pages of ‘yada_wiki’ post_type and updated the wp_term_taxonomy.count. I had the comparative luxury of it being an experimental site with a nearly exclusive focus on YadaWiki pages so that the database was not cluttered with many other types of things.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Using MySQL to Categorize and to Tag’ is closed to new replies.