Blog post filtering based on category not working


Hello,

Recently, I faced an issue while working with SP Online blog site. This issue applies to other versions of SharePoint as well.

If you are working on blogs on SharePoint platforms, you might have faced an issue when trying to filter blog posts based on category by hitting the category link shown on the Quick Launch or the category associated to the post. Doing so returns ALL posts what ever the category you asked to display (as shown below).

Steps To Reproduce:

There could be multiple reasons of this issue. Mainly, “Category.aspx” page is responsible for rendering this kind of display. You must be very cautious when doing any changes on this page. This page does not have any check-in/check-out or publishing feature so you can not revert to previous version of this page. In case you broke the linking between blog tools and other web parts it is very hard to restore it in working stage. Most of the blog sites recommend you to recreate blog site again(you will loose all blogs).

In my case, I landed up to this issues by following below two steps:

  • Go to the Posts list settings to enable Content Approval
  • Then disable the Content Approval

This has been confirmed and escalated for resolution. It appears this is because the XML query is being modified by removing the category filtering.

However, in the mean time, here is a workaround.

WORKAROUND

  • Create a blog site and do not enable the Content Approval(This step is only for getting unmodified code for reference)
  • Using SharePoint Designer open the new blog site and browse to All files\Lists\Categories and edit the category.aspx page

 

  • Open your faulty blog site and do the same (edit the category.aspx page)
  • Locate the following code (NOTE: the GUID is the specific one to your environment)

<View Name=”{F28F9AA8-7F35-4912-BAF5-1A225F33B484}” Type=”HTML” Hidden=”TRUE” ReadOnly=”TRUE” FreeForm=”TRUE” ModerationType=”HideUnapproved” DisplayName=”” Url=”/Lists/Categories/Category.aspx” Level=”1″ BaseViewID=”8″ ContentTypeID=”0x” ><Query><OrderBy><FieldRef Name=”PublishedDate” Ascending=”FALSE”/><FieldRef Name=”ID” Ascending=”FALSE”/></OrderBy></Query><ViewFields><FieldRef Name=”Title”/><FieldRef Name=”Body”/><FieldRef Name=”Author”/><FieldRef Name=”PostedByWithDate”/><FieldRef Name=”CategoryWithLink”/><FieldRef Name=”Permalink”/><FieldRef Name=”EmailPostLink”/><FieldRef Name=”NumCommentsWithLink”/><FieldRef Name=”PublishedDate”/><FieldRef Name=”PostCategory”/><FieldRef Name=”AverageRating”/><FieldRef Name=”RatedBy” Explicit=”TRUE”/><FieldRef Name=”Ratings” Explicit=”TRUE”/></ViewFields><RowLimit Paged=”TRUE”>10</RowLimit><JSLink>sp.ui.blogs.js</JSLink><XslLink>blog.xsl</XslLink><Toolbar Type=”None”/></View>

  • Add the following code after the </OrderBy> and before the </Query> tags

<Where><And><And><In><FieldRef Name=”PostCategory” LookupId=”TRUE”/><Values><Value Type=”Integer”><IfEqual><Expr1><GetVar Scope=”Request” Name=”CategoryId”/></Expr1><Expr2/><Then>-1</Then><Else><GetVar Scope=”Request” Name=”CategoryId”/></Else></IfEqual></Value></Values></In><Leq><FieldRef Name=”PublishedDate”/><Value Type=”DateTime”><Today/></Value></Leq></And><Eq><FieldRef Name=”_ModerationStatus”/><Value Type=”ModStat”>0</Value></Eq></And></Where>

  • which then looks like

<View Name=”{F28F9AA8-7F35-4912-BAF5-1A225F33B484}” Type=”HTML” Hidden=”TRUE” ReadOnly=”TRUE” FreeForm=”TRUE” ModerationType=”HideUnapproved” DisplayName=”” Url=”/Lists/Categories/Category.aspx” Level=”1″ BaseViewID=”8″ ContentTypeID=”0x” ><Query><OrderBy><FieldRef Name=”PublishedDate” Ascending=”FALSE”/><FieldRef Name=”ID” Ascending=”FALSE”/></OrderBy><Where><And><And><In><FieldRef Name=”PostCategory” LookupId=”TRUE”/><Values><Value Type=”Integer”><IfEqual><Expr1><GetVar Scope=”Request” Name=”CategoryId”/></Expr1><Expr2/><Then>-1</Then><Else><GetVar Scope=”Request” Name=”CategoryId”/></Else></IfEqual></Value></Values></In><Leq><FieldRef Name=”PublishedDate”/><Value Type=”DateTime”><Today/></Value></Leq></And><Eq><FieldRef Name=”_ModerationStatus”/><Value Type=”ModStat”>0</Value></Eq></And></Where></Query><ViewFields><FieldRef Name=”Title”/><FieldRef Name=”Body”/><FieldRef Name=”Author”/><FieldRef Name=”PostedByWithDate”/><FieldRef Name=”CategoryWithLink”/><FieldRef Name=”Permalink”/><FieldRef Name=”EmailPostLink”/><FieldRef Name=”NumCommentsWithLink”/><FieldRef Name=”PublishedDate”/><FieldRef Name=”PostCategory”/><FieldRef Name=”AverageRating”/><FieldRef Name=”RatedBy” Explicit=”TRUE”/><FieldRef Name=”Ratings” Explicit=”TRUE”/></ViewFields><RowLimit Paged=”TRUE”>10</RowLimit><JSLink>sp.ui.blogs.js</JSLink><XslLink>blog.xsl</XslLink><Toolbar Type=”None”/></View>

  • Save the page, the category filtering is working again

To finalize the operation, open the category.aspx page with your web browser to remove the Blog Tools webpart which will be in error and add it again.

Happy SharePointing !!!