Change ordering of posts/topics
Quote from Jim on April 13, 2022, 7:53 pmQuote from Jim on February 5, 2022, 9:24 pm@asgaros
Is it somehow possible to force the filter
asgarosforum_filter_get_posts_order
asgarosforum_filter_get_posts_order to act on just one topic or forum?
I finally figured out how change the order of posts in a single forum. It’s trial and error because I still don’t understand object-oriented programming 😉 I would appreciate if anyone could comment as to whether this is a bad way to do it for some reason.
/* * Put newest posts first, but ONLY in jobs forum * */ function fp_sort_posts_newest_first($order) { global $asgarosforum; if ( $asgarosforum->current_forum == 1281 ) { $order = 'p1.id DESC'; } return $order; } add_filter('asgarosforum_filter_get_posts_order', 'fp_sort_posts_newest_first');
Quote from Jim on February 5, 2022, 9:24 pmIs it somehow possible to force the filter
asgarosforum_filter_get_posts_order
asgarosforum_filter_get_posts_order to act on just one topic or forum?
I finally figured out how change the order of posts in a single forum. It’s trial and error because I still don’t understand object-oriented programming 😉 I would appreciate if anyone could comment as to whether this is a bad way to do it for some reason.
/* * Put newest posts first, but ONLY in jobs forum * */ function fp_sort_posts_newest_first($order) { global $asgarosforum; if ( $asgarosforum->current_forum == 1281 ) { $order = 'p1.id DESC'; } return $order; } add_filter('asgarosforum_filter_get_posts_order', 'fp_sort_posts_newest_first');
Quote from arathra on June 10, 2022, 11:45 amI implemented this but the sticky posts are not shown first. They are lumped with the rest of the posts in date DESC order. How can I show firstly the sticky posts and then the normal posts newest first?
function custom_asgarosforum_filter_get_threads_order($order) { if ($current_post == "topic-sticky") { $order = 't.id DESC'; return $order; } else { $order = 't.id DESC'; return $order; } } add_filter('asgarosforum_filter_get_threads_order', 'custom_asgarosforum_filter_get_threads_order');Many thanks!
I implemented this but the sticky posts are not shown first. They are lumped with the rest of the posts in date DESC order. How can I show firstly the sticky posts and then the normal posts newest first?
function custom_asgarosforum_filter_get_threads_order($order) { if ($current_post == "topic-sticky") { $order = 't.id DESC'; return $order; } else { $order = 't.id DESC'; return $order; } } add_filter('asgarosforum_filter_get_threads_order', 'custom_asgarosforum_filter_get_threads_order');
Many thanks!
Quote from Jim on June 10, 2022, 9:37 pmI’m not sure what the complete answer is, but note that you are using a filter designed to sort threads, not posts within a thread. Also, your two conditions have the same order, which doesn’t make sense.
I’m not sure what the complete answer is, but note that you are using a filter designed to sort threads, not posts within a thread. Also, your two conditions have the same order, which doesn’t make sense.
Quote from didotx on June 26, 2022, 10:41 amHi, I have been reading all the posts in this topic “ Show newest topics first in forum” and followed the instructions, but NO success!
To make sure, you understand, what I have in mind, let me explain it, based in this thread:
- This thread was created on 1/24/2017 and shows a first post #1 by Asgaros and reads “The available filters allow you to change the odering of your posts and topics ….”
- There is a second post created on 1/24/2017 post #2 by Andreas
- …. and so on ….
- and finally you can see my post from today 6/26/022 as post #24
I need to change the display sequence in such a way, that when you open the thread my post #24 is always displayed first (on the top) and post #1 is displayed last (on the very bottom).
I have added this code to my functions.php:
// Change order of posts in asgaros forum to newest first, added by dieterk on 2022-06-14
function custom_asgarosforum_filter_get_threads_order($order) {
$order = ‘t.id DESC’;
return $order;
}
add_filter(‘asgarosforum_filter_get_threads_order’, ‘custom_asgarosforum_filter_get_threads_order’);but nothing has changed.
What did I do wrong? Please help!
Hi, I have been reading all the posts in this topic “ Show newest topics first in forum” and followed the instructions, but NO success!
To make sure, you understand, what I have in mind, let me explain it, based in this thread:
- This thread was created on 1/24/2017 and shows a first post #1 by Asgaros and reads “The available filters allow you to change the odering of your posts and topics ….”
- There is a second post created on 1/24/2017 post #2 by Andreas
- …. and so on ….
- and finally you can see my post from today 6/26/022 as post #24
I need to change the display sequence in such a way, that when you open the thread my post #24 is always displayed first (on the top) and post #1 is displayed last (on the very bottom).
I have added this code to my functions.php:
// Change order of posts in asgaros forum to newest first, added by dieterk on 2022-06-14
function custom_asgarosforum_filter_get_threads_order($order) {
$order = ‘t.id DESC’;
return $order;
}
add_filter(‘asgarosforum_filter_get_threads_order’, ‘custom_asgarosforum_filter_get_threads_order’);
but nothing has changed.
What did I do wrong? Please help!
Quote from didotx on June 26, 2022, 11:11 amIt WORKS !!!
After completing this post, I checked everything again and found the problem myself. I wanted the posts sorted and not threads. Therefore I added the following code to functions.php and now it works!
// Change order of posts in topic in asgaros forum to newest first, added by dieterB on 2022-06-26function custom_asgarosforum_filter_get_posts_order($order) {$order = ‘p1.id DESC’;return $order;}add_filter(‘asgarosforum_filter_get_posts_order’, ‘custom_asgarosforum_filter_get_posts_order’);
It WORKS !!!
After completing this post, I checked everything again and found the problem myself. I wanted the posts sorted and not threads. Therefore I added the following code to functions.php and now it works!
// Change order of posts in topic in asgaros forum to newest first, added by dieterB on 2022-06-26function custom_asgarosforum_filter_get_posts_order($order) {$order = ‘p1.id DESC’;return $order;}add_filter(‘asgarosforum_filter_get_posts_order’, ‘custom_asgarosforum_filter_get_posts_order’);
Quote from JohnStaples on June 17, 2024, 5:48 amI’ve tried this and it does not seem to work any more. Can someone please confirm if this has changed?
UPDATE: I got this working but I still do not completely understand why! 😀 Thanks to @jim for his code above that I changed slightly to get it to do what I needed. Working code below.
/* Put newest posts first, regardless of recent replies, but ONLY in songs forum */
function custom_asgarosforum_filter_get_threads_order($order) {
global $asgarosforum;
if ( $asgarosforum->current_forum == 1 ) {
$order = ‘t.id DESC’;
}
return $order;
}
add_filter(‘asgarosforum_filter_get_threads_order’, ‘custom_asgarosforum_filter_get_threads_order’);
I’ve tried this and it does not seem to work any more. Can someone please confirm if this has changed?
UPDATE: I got this working but I still do not completely understand why! 😀 Thanks to @jim for his code above that I changed slightly to get it to do what I needed. Working code below.
/* Put newest posts first, regardless of recent replies, but ONLY in songs forum */
function custom_asgarosforum_filter_get_threads_order($order) {
global $asgarosforum;
if ( $asgarosforum->current_forum == 1 ) {
$order = ‘t.id DESC’;
}
return $order;
}
add_filter(‘asgarosforum_filter_get_threads_order’, ‘custom_asgarosforum_filter_get_threads_order’);