Programetically add tags to posts (2 posts)

  1. willx
    Posted 4 years ago #

    Ok so I'm writing a piece of php code that will automatically give (add) tags to posts based on logics.

    Quick example: Any post that has "Europe" in either the post_content or post_title should be tagged with "Europe".

    I've gotten as far as to be able to get all the post_id's from all posts that need to be tagged, I got the id of the post_tag "Europe", and if it doesn't exist I will first insert it and then get the ID, but I've come across a problem.

    The problem is: when I update the tables:
    To completely match what is needed, this meaning:
    - (optional: insert into wp_terms if not exists) and get the term_id
    - (optional: insert into wp_term_taxonomy if not exists) and get the term_taxonomy_id
    - (optional: insert into wp_term_relationships if not exists AND increase the "count" in wp_term_taxonomy by 1)

    However! wordpress does not tag the post, but everything in the database is correctly edited/inserted....

    What am I not seeing?

  2. willx
    Posted 4 years ago #

    Also tried things like using the function


    It does exactly the same as my own code does (makes all the connections/inserts everything in the database) -- but it does not REALLY add the tags to the post... Everything is fine in the database, but when I view the posts tags in wp-admin, it just doesn't show any tags at all...

    What am I missing/overseeing?

    [ Please do not bump, it's not permitted here. ]

Topic Closed

This topic has been closed to new replies.

About this Topic