Please or Register to create posts and topics.

Change ordering of posts/topics

PreviousPage 3 of 3
Quote from Jim on February 5, 2022, 9:24 pm

@asgaros

Is it somehow possible to force the filter asgarosforum_filter_get_posts_orderasgarosforum_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');

 

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!

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.

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!

 

 

 

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-26
function 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');

 

cauesocial has reacted to this post.
cauesocial
PreviousPage 3 of 3