Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
requests-topic
Create Post Sort Order by Forum
Avatar
Dietmar Herian
Member
Free Members
sp_UserOfflineSmall Offline
Sep 12, 2012 - 1:02 am

Yellow Swordfish said
The quickest and easiest way to confine your sort change to a single forum would be:

add_filter('sph_forumview_query', 'my_sort_function');
function my_sort_function($sqlObj) {
    global $sfvars;
    if($sfvars['forumid'] == XX) {
        $sqlObj->orderby = SFTOPICS . '.topic_name ASC';
    }
    return $sqlObj;
}

Where XX is the forum ID you want to effect.

Hi SP-team,

I also do have some users who want to have influence in sorting posts preferably as  user profile option. Mainly, it is reverse sorting by date - oldest first. I could use the code sample with variation of sorting parameter Is there any document describing this? And how can I find out the forum ID?

"Computers in the future may weigh no more than 1.5 tons."
(Popular Mechanics, US-Technik-Magazin, 1949)

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Sep 12, 2012 - 3:26 am

Not documented as such - no. But for posts, a similar type approach could be made. The filter to use would be 'sph_topicview_query' and the sql query would be against the SFPOSTS table using the post_id as the sort column.

You can find the forum ID in the forum listing in the forum admin.

Not sure how you would make it a user option though. Although you may be able to do this with a custom profile field.

andy-signature.png
YELLOW
SWORDFISH
Avatar
Dietmar Herian
Member
Free Members
sp_UserOfflineSmall Offline
Sep 12, 2012 - 11:34 am

Yes, this would be the way to do it. I'll make it a radio button.

After browsing through forum and documents, I only found this explaining how to read user profile data by programm.

I assume that this is outdated for V5.

What is the V5 name of the function ? Did not find anything searching for 'sp_profile_get_data' or similar.

I guess the array is similar ? Anyhow, if I knew the function, I can get it printed via wp_mail.

"Computers in the future may weigh no more than 1.5 tons."
(Popular Mechanics, US-Technik-Magazin, 1949)

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Sep 12, 2012 - 12:12 pm

Yes the old wiki only goes up to V4 I am afraid.

So - are you after the user data? If you go to the forum admin > Toolbox > Data Inspector and turn on the option to display spThisUser it will display it for you when you run the forum. You will be the only user to get this display. This will show you the data object available for the current user. It will include any custom profile fields.

andy-signature.png
YELLOW
SWORDFISH
Avatar
Dietmar Herian
Member
Free Members
sp_UserOfflineSmall Offline
Sep 12, 2012 - 2:20 pm

Sorry, I was not clear enough :

I am after the replacement for the function

$profile = sfc_get_profile_data( $userid )

What is the new name for V5? I need it for my php code.

Thanks for the hint to the data inspector. I will need it, too.

"Computers in the future may weigh no more than 1.5 tons."
(Popular Mechanics, US-Technik-Magazin, 1949)

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Sep 12, 2012 - 2:52 pm

There is no function. For the current user you simply globalise the $spThisUser object and use that. If it is not the current user you want you best tell me and I can point you in the right direction.

andy-signature.png
YELLOW
SWORDFISH
Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Sep 12, 2012 - 8:32 pm

if you want to specify the user, it would be:

    $thisUser = sp_get_user($userid);

where $userid contained the user id of the user...  if you are on a profile page, you could try:

        sp_SetupUserProfileData($userid);

which would actually populate the global variable $spProfileUser...

Avatar
Dietmar Herian
Member
Free Members
sp_UserOfflineSmall Offline
Sep 13, 2012 - 9:48 am

Thanks a lot guys for your really excellent support.

I have implemented it now as a custom profile checkbox field where user can individually choose to sort posts in 'reverse' order - meaning oldest post first. And it works like a charm!

Hope they are happy now! Well, at least for a while!

Here is my piece of code in spFunctions.php of my SP-Theme:

function my_sort_function($sqlObj) {
        global $sfvars, $spThisUser;
//        $test = $spThisUser->sortierealtestenpostnachoben;       
    if($spThisUser->sortierealtestenpostnachoben) {
            $sqlObj->orderby = SFPOSTS . '.post_date ASC';
        }
        return $sqlObj;
    }

where 'sortierealtestenpostnachoben' is the slug name of the custom profile checkbox.

"Computers in the future may weigh no more than 1.5 tons."
(Popular Mechanics, US-Technik-Magazin, 1949)

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Sep 13, 2012 - 10:15 am

I am impressed!

You are clearly one of the rare users who seems to have the posts sorted with the most recent at the top. I am afraid I am with your users on that one - I prefer the oldest first....

andy-signature.png
YELLOW
SWORDFISH
Avatar
Dietmar Herian
Member
Free Members
sp_UserOfflineSmall Offline
Sep 13, 2012 - 10:55 am

Well, we have around 225 users in our small community of which 3 have requested to sort the 'oldest on top' way.

Seems that 'most recent on top' is kinda German standard (because of scrolling reasons) and it is the same in many other blogs I know and use.

Ok, ok, we also drive on the right hand side of the road - strange enough! :) 

De gustibus et coloribus non est disputandum!

"Computers in the future may weigh no more than 1.5 tons."
(Popular Mechanics, US-Technik-Magazin, 1949)

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: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 619
Members: 17362
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10127
Posts: 79625