• I have a lot of posts already uploaded into the database, and now I need to attach a lot of post-tag and category taxonomies to them (not the same on all posts).

    It’s not practical to modify all the posts individually. I have the information in a data file, and can run it through a process to generate SQL to run, but it seems the documentation is biased towards doing things through the php functions.

    I want to make sure I’m correctly inserting into wp_terms, wp_term_taxonomy, and wp_term_relationships. Can I get some quidance on this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • You did not say how many tags and categories you need to add. If not too many, you could create them using the WP Admin panel. Then you could use the term_taxonomy_id’s in your sql to insert into term_relaionships. That will simplify your sql.

    The other tricky part will be getting the post ID’s. Since not every post needs the same terms, you must have some way to select the correct posts to receive each term.

    Without more detail, I cannot be more specific.

    Thread Starter Cipherlad

    (@cipherlad)

    About 200 categories, and many more tags, connected to between 2000-3000 thousand existing posts. Like I said, not practical to do it manually.

    I can determine the post IDs. That’s not an issue. The whole project is a little complex, but suffice to say I’m generating an in-memory collection of the post information with a collection of categories and tags (just the strings) that may or may not exist already in the database.

    I’d love to just have a database function or procedure I could pump these into, but I couldn’t find anything like that. I think right now my biggest caution is the slug field in wp_terms. That’s unique in the database, but I don’t know what the slug generating code is like. I’ll need to be able to insert into wp_terms and query back for the term_id, and slug is the only field I can query on to get that result.

    I think the WP 3.1.3 code to create slugs is in wp-includes/formatting.php at line 831, function sanitize_title_with_dashes.

    Maybe you can get what you need from there.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Adding new Terms/Taxonomies via SQL only’ is closed to new replies.