Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
coding-topic
Manually changing a post position in a topic thru database
Avatar
sptab
Member
sp_UserOfflineSmall Offline
Apr 24, 2012 - 4:32 am

Hello,

I have a specific situation where I need to insert a post in topic at a specific position in the posts list.

This post should go in position #2 in a topic that has 9 posts.

What I have done is the following:

- create a new post in the topic in the forum

- change the post_index in wp_sfposts table for my new post, change the following posts according (older post 2 becomes 3, 3 becomes 4 and so on)

- change post_count and post_id in wp_sftopics table to reflect my new post change

Unfortunately, my "inserted post #2" stays at the end of the post list, like it's the newest post. (I also tried changing post_date for my post to insert in wp_sfposts table, it did not help)

What else would be required to move it to second post position in the topic posts list ?

Thank you.

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Apr 24, 2012 - 5:15 am

Good try... but. Well you found the but! Topics are actually ordered by their post_id. This is because firstly it does truly represent the order hey were posted in and secondly because being the primary key it is the quickest column on which to sort.

Now - while I am not necessarily recommending it - you can actually change that with a small function in your theme functions file, to use postindex instead. This should be OK - and I stress should be. Put it this way - if it failed then there would need to be some clean up of data anyway! Such a change would also apply to all topics.

If you want to try that I can tell you what you need to do...

andy-signature.png
YELLOW
SWORDFISH
Avatar
sptab
Member
sp_UserOfflineSmall Offline
Apr 25, 2012 - 2:13 am

Well, I made the change on the post_id: had to change the autoincrement on the table and renumber all the post_ids after my inserted post.

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Apr 25, 2012 - 3:51 am

Wow. More difficult but safer in the long run.

andy-signature.png
YELLOW
SWORDFISH
Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 649
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 618
Members: 17357
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10123
Posts: 79616