Skip to content

Filter a Content Query Web Part by Page Field Values or Query String Values in SharePoint 2010

by on August 9, 2011
  1. Create a page in Site Pages or Pages called “Test CQWP Filters”
  2. Add the CQWP to your page
  3. Select the web part > hover over the arrow > Click on Edit Web Part (if it is a new web part or returns no results, you can also click on the Open Tool Pane link that will appear)
  4. Expand the Query section of the Tool Pane
  5. Select Show items from the following list and specify the Pages or Site Pages library
  6. Next to Additional Filters, click on the question mark icon – this gives you a rundown of how to employ page and field filters

Filter a CQWP by a Page Field Value

You can filter by a custom page field/page property that has already been added to the Pages/Site Pages library. In this case “Topic” contains a single topic called “My Topic”. Add the following to Additional Filters:

  1. Show Items When: Topic
  2. set dropdown appropriately – I am using “is equal to”, this means it must match exactly
  3. Type in: [PageQueryString:Topic]
  4. Click on Apply
  5. The CQWP should now display all pages with the topic “My Topic”

Filter a CQWP by a Query String Value

  1. Show Items When: Topic
  2. Set dropdown appropriately – I am using “contains” NOTE: This is so Topic can have multiple values, as with a checkbox selection field
  3. Type In: [PageFieldValue:Topics]
  4. Click on Apply
  5. In the address bar, add the query string parameters to the end of the address in the following format: http://mysite.com/pages/test-cqwp-filters.aspx?topic=My%20Topic
  6. The CQWP should now show

NOTE: Parameters are case sensitive and you must use %20 to represent spaces – if you are having trouble, check for any special characters that may also require formatting for use in the query string

Filter a CQWP by a Multiple Value Field – Not Possible?

I came across a situation where I wanted to filter the CQWP by a multiple value enabled field. In other words, the page field “Topics” should be allowed to have multiple values and you should be able to filter the field using multiple values – say show all pages containing any of the topics of this page, but this does not work as it tries to create an exact match and there is no “contains any off” option like there is if you select “All Tags” for the first value.

There does not seem to be any easy way to do this. If anyone has an answer as to how to do this, please let me know.

Advertisements
11 Comments
  1. Hello Emerson

    Ran across your post – cool stuff.

    As far as multiple-value field filtering – assuming we’re talking 2010, why couldn’t you simply use multiple filters separated by OR?

    Am I missing it?

    Thanks,
    Jason

  2. This is not possible with a multiple value field – check it out, the options change!

    • I’ll play with it more.
      In most instances, I’ve only found two scenarios:
      1. None of the available “Filter By” entites are Choice (so no possibility of multiple selection)
      2. After ensuring some kind of custom Site Column is present in the list that (one which is of type “Choice” and allows multiple selection), I see it available in the “Alternate Filters”
      A) I select the column in question (I created “Topic” for use)
      B) For each of the values in which I am interested, I select “Topic”
      C) Then is equal to
      D) and “OR” for each addititional filter after the first

      The only thing I can think of to which you might be referring is the lack of a reverse filter.
      In other words, given a choice column, there’s no way to filter by multiple values simultaneously.
      If that is what you were referring to, then I suspect there’s a way to do it via SharePoint Designer – but you’d potentially impact a number of other web parts.

      So, how am I misunderstanding what you’re saying?
      Please do let me know!

  3. ericstepek permalink

    Great article! One other item to note is that it appears the field type in the filter need to be the same. I tried filter to see if text in a Single Line of Text field is contained (“Contains”) in an HTML Publishing field (which is really just enhanced text). It would not work until the source (“Contains”) field was also a Single Line of Text.

    • emersonbruce permalink

      yes, this can be an issue. There is also a lot of hidden code in the rich/enhanced text fields, so I am not sure if it is a conflict directly between those two fields, or if it is due to hidden html code. For example if there is a bold, underline, italic, link, etc. it has the underlying code actually in the comparison text. The comparison is also case sensetive.

      “hello all” is not equal to “hello all” or “Hello All”

      If I have a moment, it would be nice to check out the text/html comparisons further! Thanks for the info!

  4. Brian permalink

    You can do a multiple value field in a filter, but I could never get the webpart toolpart to display it correctly afterwards. The filter does work however, for example:

    TaxKeyword, Enterprise Keywords
    TaxKeyword
    TaxonomyFieldTypeMulti
    [PageFieldValue:23f27201-bee3-471e-b2e7-b64fd8b7ca38:TaxKeyword:TaxonomyFieldTypeMulti]
    [PageFieldValue:Enterprise Keywords]
    ContainsAny

  5. Jim permalink

    Hi Emmerson,

    Were you able to find a solution to allow multiple value fields to a CQWP?

    • No, sorry, looks like this would require some custom code, which I prefer to avoid if possible.

      I am sure there’s a solutions, just never had the time or the lightbulb moment. Please share if you come up with something!

  6. Saurabh permalink

    Is there any solution of this problem. I have a ‘category’ field which is of multi-choice type (checkboxes). I want to show the “Related Content” in CQWP based on Category field. I have to show all list items where Category Field contains – “First” value of “Category” Column of current page.

    • There is always a way – it just depends how much time and effort (IE. money) you want to spend.

      I am not sure I understand what you are trying to filter by… could you explain in more detail?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: