Adding a secondary orderby parameter that isn't sorted by the alpha_field
Basically, we're using alphabet to display a set of exhibitors, and it's doing that well.
We've just had a request that some of these exhibitors can pay a premium to appear at the top of the listings. I saw a previous topic on stickiness and this is kind of the functionality that would do the trick but it looks like thats a fair job for you to do. Besideswhich, I'm using a custom field to make if they're a premium account or not. So...
I tried using the custom field in the orderby parameter like so:
orderby="has_premium_account|title"
This work's OK on the initial listing (no alpha filter) but as soon as I use an alpha to filter it out then I get no results (except on the Y and N pages). Reading though the docs it seems that's exactly what's meant to happen:
All fields entered in the orderby parameter will be treated as though they were alpha fields.
Ideally, I'd set up the params like so:
orderby="has_premium_account|title"
sort="desc|asc"
Which would sort the entry's with the Yes's coming first in alphabetical order (from the title) and then the No's after that. Do you know of anyway to get this functionality with your add on? Or could I do this with the query module or something?
Thanks
Dave
Replies
Low 23 Feb 2012 10:28
Hi Dave,
The behavior you describe should already be possible. As long as all the entries have the value Yes or No in the has_premium_account field (it shouldn't be empty), it should work. A test I just did confirms that.
Dave O'Brien 23 Feb 2012 12:16
Hi Low, thanks for getting back to me.
I've just checked again and unless there's something up with my code I'm not getting that.
Basically if I visit the A page, then I will get no results with this orderby:
orderby="has_premium_account|title"
If I remove the 'has_premium_account' field then I get entries beginning with A which is correct.
I think that as the 'has_premium_account' is first it will filter out any entries where the 'has_premium_account' field does not begin with A (all of them as they're either yes or no). I checked this by adding an A to the custom field for an entry - revisited the A page and this showed that entry.
What would be perfect for this case is the first param does not filter out any entries by t the alpha_filter, instead it only sorts alphabetically if you get what I mean?
It might be my code, but after reading the docs what is happening looks like it should be happening...
It doesn't make much sense in a normal set up but I think it would be perfect for me. Any pointers for tweaking the mod?
Low 23 Feb 2012 12:52
Ah yes, I get it now. The alpha_filter is always applied to the first field in the orderby="" parameter.
I've done a little test here, where I changed the behavior of the alpha_field="" parameter (which was pretty much obsolete anyway) to be a target for the alpha_filter="" param. In that way, you could use this:
That way the filter is only applied to the field defined in alpha_field, not the first item in the orderby parameter. Drop me an email at hi at gotolow dot com for the patched file.
Dave O'Brien 23 Feb 2012 13:07
Mate, that makes me so happy!!!
I was dreading the query I was thinking about writing. I'll drop you an email in a mo and let you know how I get on.
Dave O'Brien 23 Feb 2012 15:53
That's spot on - works a treat, thank you!
Low 24 Feb 2012 07:58
Great. I'll incorporate that into the next version.
Brax 28 Mar 2012 15:50
Is this available in 1.0.7? I have run into the EXACT same problem as Dave and tried to use the alpha_filter solution but with no success.
Low 29 Mar 2012 09:39
Ah, no, it wasn't. It's in v1.0.8, tho. :)
Brax 29 Mar 2012 15:24
Excellent!