InCategories returns no results, query contains 0=1

Stephen Dolier asked on July 11, 2018 12:35

Hi,

I have a custom page type, with a categories field type and categories selected.

In the CMS i see that the "test" category has multiple pages assigned to it.

i would like to get a list of documents with a given category selected.

when I run:

CustomPageProvider.GetCustomPages().InCategories("test").ToList()

I get a query like:

"SELECT *\r\nFROM View_CMS_Tree_Joined AS V WITH (NOLOCK, NOEXPAND) INNER JOIN custome_page AS C WITH (NOLOCK) ON [V].[DocumentForeignKeyValue] = [C].[AuthorID] AND V.ClassName = N'custome_page' LEFT OUTER JOIN COM_SKU AS S WITH (NOLOCK) ON [V].[NodeSKUID] = [S].[SKUID] nWHERE (([DocumentCanBePublished] = 1 AND ([DocumentPublishFrom] IS NULL OR [DocumentPublishFrom] <= @Now) AND ([DocumentPublishTo] IS NULL OR [DocumentPublishTo] >= @Now)) AND [DocumentCulture] = @DocumentCulture AND 0 = 1)"

note the 0=1 at the end.

Any ideas what i am doing wrong here. Or another way of doing this.

Cheers, Stephen

Correct Answer

Dragoljub Ilic answered on July 11, 2018 13:25

Hi Stephen,

If you do not specify site name in the query, it will look only for pages in global categories. If you added categories specific to the site, then you need to modify your query to look like this (you can replace hardcoded name of the site with CMS.SiteProvider.SiteContext.CurrentSiteName):

CustomPageProvider.GetCustomPages().OnSite("DancingGoat").InCategories("test").ToList()

To verify that you properly assigned your categories on the page, you can check it in 'Pages' application, on 'Categories' tab (under properties).

Best regards, Dragoljub

0 votesVote for this answer Unmark Correct answer

Recent Answers


Peter Mogilnitski answered on July 11, 2018 15:36

I would you DocumentHelper

// Get documents from Development category
var documents = DocumentHelper.GetDocuments("YourCustomPageType")
                              .OnSite("CorporateSite")
                              .InCategory("test");
0 votesVote for this answer Mark as a Correct answer

Stephen Dolier answered on July 11, 2018 23:31

Thanks Guys,

Adding OnSite to the query solved the problem.

Cheers, Stephen

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.