The Content Query WebPart (CQWP) is great for quick ‘Data View’ style content roll-ups, and is very easy to configure. Very easy to choose the WEB, and LIST and CONTENT TYPE to use.
But – it’s a little limited, in that you can only have THREE set of filter criteria.
Edit Page > Edit WebPart > Query
Once you’ve hit that limit – then you almost need to start all over again – using SharePoint Designer – and add a DataView or ListView webpart.
BUT – there is a way you can include MORE filter criteria – and you don’t have to change the other settings within the CQWP you’ve got in place – often important with regard to style/layout/etc.
Here’s the steps to do it :
- Edit Page > Export WebPart
- Save it somewhere you’ll remember – eg. SPR1.webpart
- Open the file in Notepad – or within Visual Studio (easier to see/read)
- You’ll see the FILTER fields within there :
- FilterField1, FilterField2, FilterField3
- FilterDisplayValue1, FilterDisplayValue2, FilterDisplayValue3
- FilterValue1, FilterValue2, FilterValue3
These will be populated depending on what you’ve chosen in the CQWP user interface (as above)
There is another property in there entitled : QueryOverride
<property name="QueryOverride" type="string" />
This can be used to add MORE filters (where clause) and will be used instead of the 1,2,3 filters.
You just need to (eek) define the CAML to put inside the property – and then save the .WEBPART.
Here’s an example that I pieced together :
<property name="QueryOverride" type="string">
<FieldRef Name="Document_x0020_Type" />
<FieldRef Name="Meeting_x0020_Category" />
<Value Type="Text">Board Meeting</Value>
<FieldRef Name=’Created’ Ascending=’FALSE’ />
It looks like a LOT – but it essentially does this :
WHERE (PublishDate < TODAY or PublishDate = NULL)
AND (ExpiryDate > TODAY or ExpiryDate = NULL)
AND (Document Type = Notice)
AND (Meeting Category = Board Meeting)
ORDER BY Created DESC
So – we can use that XML (CAML) within the CQWP webpart – by replacing the “QueryOverride” tag.
Next step is to copy that piece of XML into the .WEBPART file – and save it.
** Remember to include the CDATA tags – and also – ditch the original “QueryOverride” tag.
Also – remember that the 1,2,3 filter values are now IGNORED – so you’ll have to do it ALL in the CAML query.
Now, go add the updated webpart to the page :
- Edit Page
- Add WebPart
- Import WebPart > Browse
- Choose the file (.WEBPART)
- Click Upload
- THEN – have to re-click the “Add WebPart” button (this step is a little crap, IMHO)
- And then you’ll see it listed in the “Imported WebParts”
And – that’s it – hopefully (if you master’ed the CAML), it should be working OK.
If you’re having trouble with CAML, a good approach is to use SharePoint Designer – add a ListViewWebPart, and then add some filter values – via the point+click UI.
Then – switch to CODE VIEW – and see what it’s created.
OR – use the U2U CAML Builder tool.
And – there you have it – you CAN have more than THREE filter values for a CQWP – just have to use the ‘override’ property.
It’s a little tricky – but very powerful.