SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have something like this:

SPQuery query = new SPQuery();
query.Query = "<OrderBy><FieldRef name=\"MyTerm\" /></OrderBy>";

I can sort on normal fields, but it refuse to sort on my managed metadata field. Any ideas?

share|improve this question
are you able to ever solve this? having same problem – Prashant Lakhlani Mar 1 '12 at 9:49
up vote 2 down vote accepted

One thing I've noticed in 2010 is that the OrderBy won't work if you're not returning the field name explicitly in the query.ViewFields property. So try adding:

query.ViewFields = "<FieldRef name=\"MyTerm\" />";

to your code.

share|improve this answer
Thanks for you answer. I tried this, but without luck. As well as setting query.ViewFieldsOnly = true; (ref…) – eirikb Nov 29 '10 at 19:18

Maybe you can try to write 'name' as 'Name'. Does the column allow multiple values?

share|improve this answer
Not sure if 'Name' instead of 'name' would help when it works for other fields? The managed metadata field can have multiple values in this case, yes. We finally ended up just using jQuery for sorting with fallback to no sort. We also use paging with jQuery since paging + filtering is difficult – eirikb Feb 23 '11 at 11:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.