Adding more than three filters in CQWP (Ricardo Loo)


Problem

You want to roll up content from your site (and subsites), no problem, CQWP is there to help.

But, hey! the tool part UI only offers support for three filters:

image

What if you need more filters?

A (simple) solution

One way to allow for more than three filters is to override the QueryOverride property of the web part. This involves the following general steps:

  1. Export the web part to file system.
  2. Build the CAML required to filter the list.
  3. Update the QueryOverride property
  4. Import the web part to the web part page.
Export the web part to the file system

With the page in Edit Mode, expand the Content Query Web Part Menu and select Export…

Save the web part to the local file system.

image

Build the CAML required to filter the list

If you’re not comfortable with CAML there are some tools and resources that could help:

In my site there is a custom list with the following structure and items:

image

Update the QueryOverride property

If I need four filters (one for each custom column) I could use the following value in the QueryOverride property:

        <property name="QueryOverride" type="string">
          <![CDATA[
           <Where>
              <And>
                 <And>
                    <BeginsWith>
                       <FieldRef Name='NewColumn1' />
                       <Value Type='Text'>NewColumn1 Item1</Value>
                    </BeginsWith>
                    <BeginsWith>
                       <FieldRef Name='NewColumn2' />
                       <Value Type='Text'>NewColumn2 Item1</Value>
                    </BeginsWith>
                 </And>
                 <And>
                    <BeginsWith>
                       <FieldRef Name='NewColumn3' />
                       <Value Type='Text'>NewColumn3 Item1</Value>
                    </BeginsWith>
                    <BeginsWith>
                       <FieldRef Name='NewColumn4' />
                       <Value Type='Text'>NewColumn4 Item10</Value>
                    </BeginsWith>
                 </And>
              </And>
           </Where>
          ]]>
        </property>

Note you only need the Where section of the CAML query and it has to be contained within a CDATA element.

Import the web part to the web part page

With the web part page in Edit Mode, click the Add a Web Part link to open the Web Part Pane.

Under the Upload a Web Part section select the modified web part file in the local file system and click Upload. This will load your web part under the Imported Web Parts category.

image

Select your web part and click Add to import the web part into the web part page.

Additional considerations

When we use the overrides properties within the CQWP some of the elements in the UI will be disabled, in this case we cannot add more filters from the Content Query Tool Part.

image

Comments (1)

  1. cherry says:

    British reporters are known for doing almost anything to get a Mulberry Bags. But reports that a newspaper secretly listened to telephone messages of murdered schoolgirls and other private citizens have produced Mulberry Handbags and anger.

    On Friday, British police arrested Andy Coulson, former editor of Mulberry Bag Britain's best-selling newspaper, News of Mulberry Outlet the World. The investigation led him to Mulberry UK Sale resign in January as communications director to Prime Minister David Cameron.

    The arrest came in a widening investigation of Mulberry UK telephone hacking. Other accusations include paying police for mulberry shoulder bags information on stories. The Reuters news agency reported that Mr. Coulson was released on Mulberry Bag UK until a date in October.

    Prime Minister Cameron promised Men's Mulberry Bags Friday that a judge will lead a full public inquiry into Women's Mulberry Bags the case after police complete their investigation.

    DAVID CAMERON: "Murder victims, terrorist victims, families who have lost loved ones, sometimes defending our country, that these people could have had their phones hacked into, in order to generate stories for Mulberry Bags  Mulberry Handbags  Mulberry Bag   Mulberry Outlet  Mulberry UK  mulberry bayswater bag  Mulberry Alexa Bag, is simply disgusting."