In a Publishing site I have web part that has to show news items from the list that has Audience Targeting field. I am using CAML query to retrieve small number of last news items.
Is it possible to specify Target Audience in the CAML query ? If not, how should I do it ? Retrieve all results and than apply filter in a loop ?
I am practically duplicating Content Query Web Part and I need Audience Targeting in my custom web part.
No, it is not possible to specify audience targeting in a CAML query. I think this has to do with CAML queries being a WSS thing and Audiences being a MOSS Shared Service. What you have to do is to include the audience field in the CAML query, i.e. add a <FieldRef Name='Target_x0020_Audiences'/> to the SPQuery.ViewFields property. Then filter the results code wise by audience on each list item. Use the AudienceManager class to test if the current user is a member of an audience.