1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.2 Changing userid of posts

Discussion in 'XenForo Questions and Support' started by Tyrone Chicken, Dec 25, 2013.

  1. Tyrone Chicken

    Tyrone Chicken New Member

    I had to merge two boards, but one of the users ended up with the ID of 0 since I had to delete the account. Could anyone help me with a SQL query or something to change the userid on all the posts with the userid of "0"?

    For example these posts need to be changed to the userid of "1":
  2. Brogan

    Brogan XenForo Moderator Staff Member

    This is a simple query:
    UPDATE xf_post
    SET user_id = 1
    WHERE user_id = 0
    However, I don't know what associated data needs to be updated.

    You will likely need to rebuild post and like counts (there are queries posted for that).

    You may also need to rebuild caches and the search index.

    In general, I wouldn't recommend changing data by directly editing the database.
    Tyrone Chicken likes this.
  3. snoopy5

    snoopy5 Well-Known Member


    I have a similar situation. But there are different usernames with userid of 0. Some of them even do not show up with username in the table xf_users. This is because I had several vb and photopost before and imported them into xf.

    What kind of queries do I have to use to make an if-then statement? Let's say if username is=smith, then make userid=59999. For the next username , i would then use a different userid which is not yet in use.

    How could I do this with phpmyadmin?
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    snoopy5 likes this.
  5. snoopy5

    snoopy5 Well-Known Member

    Thanks Jake, that code did exactly what I needed to do.

Share This Page