XF 2.2 Sort threads by last_post_date and?

Robert9

Well-known member
The sort of threads is
SELECT * FROM xf_thread
ORDER BY last_post_date DESC, last_post_id DESC ?
 
Last edited:
It's not clear what the issue or question is.

You originally posted this in troubleshooting.

What are you trying to do/determine?
 
My last ten threads have the same last_post_date.

In forum_view they have a fixed order.

But when i try to fetch the next and prev threads, i need the following code to get a result that fits to the list of threads in forum_view

Code:
        $myThread = $threadFinder

                ->whereOr([
                        ['last_post_date', '>', $postDate],
                    ],[
                        ['last_post_date', '=', $postDate],
                        ['last_post_id', '>', $lastPostId],
                    ])

                ->where('node_id', $forumId)
                ->where('discussion_state', 'visible')
                ->where('discussion_type', '<>', 'redirect')
                ->setDefaultOrder(['last_post_date', 'ASC'], ['last_post_id', 'ASC'])

                ->fetchOne();

        return $myThread;

Conclusion: there must be a second order for threads, when sorted by last_post_date like

Code:
ORDER BY last_post_date DESC, last_post_id DESC ?

(I could not find that in the xf code)
 
My last ten threads have the same last_post_date.

In forum_view they have a fixed order.

But when i try to fetch the next and prev threads, i need the following code to get a result that fits to the list of threads in forum_view

Code:
        $myThread = $threadFinder

                ->whereOr([
                        ['last_post_date', '>', $postDate],
                    ],[
                        ['last_post_date', '=', $postDate],
                        ['last_post_id', '>', $lastPostId],
                    ])

                ->where('node_id', $forumId)
                ->where('discussion_state', 'visible')
                ->where('discussion_type', '<>', 'redirect')
                ->setDefaultOrder(['last_post_date', 'ASC'], ['last_post_id', 'ASC'])

                ->fetchOne();

        return $myThread;

Conclusion: there must be a second order for threads, when sorted by last_post_date like

Code:
ORDER BY last_post_date DESC, last_post_id DESC ?

(I could not find that in the xf code)
Well you see the setDefaultOrder function in that bit of code, it does the ordering.
You just need to change the conditions there.

Clément
 
Back
Top Bottom