Support Forum

Topics order in forum, seems not to work

GI Giovanna
Giovanna
Member

Hello,
this is the first time I notice this happening: the last 3 topics in a forum are not ordered correctly from the most recently created onwards. I cannot work out why, so I attach you 2 screenshots: the display settings and the forum view. It is in Italian but I think you can understand (giorni = days, ore = hours, settimana = week. The dates in the topic titles are the real creation dates of the topic itself and I checked they are the same as the real topic dates (can make more screenshots if you like, please let me know).
How can I solve this please? Thanks and have a good day!

 

forum-view-order-options.jpg 

wrong-date-order.jpg

28 Answers

New Answer

YS Yellow Swordfish
Yellow Swordfish
Member

I am not totally sure what you are meaning so perhaps if I describe how things are naturally sorted then you can tell me if this is what you were expecting!

Simple:Press follows the common practice in forums of sorting topics by their most recent reply. So if an old topic receives a new post, that topic will bubble back to the top of the topic listing etc..

So – is that not what is happening here? Or is that not what you want to happen?

GI Giovanna
Giovanna
Member

oh… so far it seemed it ordered by latest creation date. In fact if I add a reply to an earlier post it did not use to appear at the top of the topic. I remember setting it like this at the beginning and then I never paid too much attention but I think I would have noticed and today is the first time I see this happening…

In any case what I would like is to be able to have the topics in some forums ordered always for creation date ascending, is that possible?

YS Yellow Swordfish
Yellow Swordfish
Member

This is the way it has always been. The sort options you can change (as far as the forum view is concerned) is to reverse the default so that the oldest topic remains at the top of the list working down to the newest one. An odd thing but apparently some people like this.

What – I believe – you are asking for, is newest topics to be added to the top of the listing (as happens) but sorted by their FIRST post instead of their LAST post (which is the standard). Is that correct.

We should be able to do this with a simple filter. I will take a look this morning. I do wonder if such an option would be popular… I believe we have had one other user in the past request this…

YS Yellow Swordfish
Yellow Swordfish
Member

By the way – do you use an SP child theme? AND – you say in ‘some forums’. I will need to know the forum IDs of those you want to change.

GI Giovanna
Giovanna
Member

ehm… I am not sure that we understand each other, maybe a problem with the jargon which surely I tend to misuse. I repeat again what I need  trying to be more precise…

In 4 of my forums every day or week I or any other user start the post of the day, which I believe in jargon would be the “topic”. I need, when the forum is accessed, to be viewed in ascending order of the creation date of these posts. So today I would see in order (apart from the pinned on top topics) the post of today followed by the one of yesterday and so on going back on time day by day.

Within the topic instead I need to see each users’ post from the earlier to the latter in time, which is fine as it is.

Are we saying the same thing?

As for the other questions:
– I don’t use a theme child although I have added a few lines to show the advertisments in some files.
– The ids of the 4 forums I need to view in this way are shown in this screenshot in the leftmost column I think: 

forums-ids-to-be-ordered-correctly.jpg

 

the 4 forums are in the red box. Otherwise please tell me where to find the ids. Thanks a lot for helping!

YS Yellow Swordfish
Yellow Swordfish
Member

Yes – we are saying the same thing. nd you really should use a child theme to preserve changes. But – we can work around that.

Create a new and empty file in the ‘wp-content‘ folder of your WP site named ‘sp-user-functions.php‘.

Add open and close php tags to the very top and very bottom of the ne file and add the following code:

add_filter('sph_forumview_query', 'my_topic_sort', 1, 2);
function my_topic_sort($db, $data) {
    $fids = '&5&6&17&18&';
    if ( strpos( $fids, '&'.$data->forumId.'&' )) {
        $db->orderby = 'topic_pinned DESC, spf_sftopics.topic_id DESC';
    }
    return $db;
}

Of course – you can change the function name if you wish to. That should do the trick I think. Careful with the case of variable names….

GI Giovanna
Giovanna
Member

Thanks! I will try a bit later and will lwt you know smile

GI Giovanna
Giovanna
Member

Bad news Andy… after putting the file there the forum did not display topic anymoreeek

Shall I send you the file in an MP so you see if I made any mistakes? Thanks

YS Yellow Swordfish
Yellow Swordfish
Member

The code is good – I tested it out, How did you copy and paste it? did you use the ‘raw code’ button and copy/paste the result from the popup window?

GI Giovanna
Giovanna
Member

the code looks exactly like yours plus the php tags and some comments I added, here you are:

<?php
# ————————————————————————————–
#
# Simple:Press trick to order the topis in the forums:
# 5: Pesate settimanali
# 6: Diario Alimentare
# 17: Diario: commenti e domande
# 18: Pesate: commenti e domande
# in ascending order for the creation date.
# This file has been created by hand, named sp-user-functions.php and
# put into the wp-content folder of mspforum.
# The whole thread on the support forum is at this link:
# https://simple-press.com/support-forum/sp5-general-topics/topics-order-in-forum-seems-not-to-work/#p159916
#
# ————————————————————————————–
add_filter(‘sph_forumview_query’, ‘my_topic_sort’, 1, 2);
function my_topic_sort($db, $data) {
$fids = ‘&5&6&17&18&’;
if ( strpos( $fids, ‘&’.$data->forumId.’&’ )) {
$db->orderby = ‘topic_pinned DESC, spf_sftopics.topic_id DESC’;
}
return $db;
}

?>

I had to add it directly under the wp-content folder right? That sounded a little strange that’s why I ask again…

IK Ike
Ike
Member

I’ve never used sp-user-functions.php, but I think it’s contents just get added to the regular functions file meaning you shouldn’t need the PHP tags.. It’s future proof as it won’t be overwritten.

MP Mr Papa
Mr Papa
Member

Andy’s question about how you copied it still applies… if you copied the text directly in the post, you probably got some invalid characters…  you must view the raw code and copy it from the popup to ensure you dont get the invalid chars..

GI Giovanna
Giovanna
Member

I don’t understand what you mean with “raw code”. I used notepad and edited the code, which I then copied and pasted here. Can you please explain? Thanks and goodmorning!smile