I have the following Sitecore queries:
- /sitecore/content/Home/Clubs//17th
- /sitecore/content/Home/Clubs//20th
Of specific note is I'm using the descendant axes feature of the Sitecore Query language (//), with /sitecore/content/Home/Clubs being my context.
I have my content structured as such:
- /sitecore/content/Home/Clubs/Chicago/17th
- /sitecore/content/Home/Clubs/New-York/Downtown/20th
When I run queries 1 and 2 in XPath Builder, I get content items 1 and 2; respectively. This is what I expect. However, when I run those same queries through Sitecore's API, I get a content not found error.
The following queries will work with Sitecore's API, mind you:
* /sitecore/content/home/clubs/*/17th
* /sitecore/content/home/clubs/*/*/20th
What I'm trying to accomplish is one query where I can get both children AND grandchildren of a content item with a specific name; a query like this:
/sitecore/content/Home/Clubs//{contentItemName}
I know I could just try
/sitecore/content/Home/Clubs/*/{contentItemName}
and fallback to
/sitecore/content/Home/Clubs/*/*/{contentItemName}
if that doesn't work, but that seems like a hack.
Is there anyway I can get the query I verified in the XPath builder works to work with the Sitecore API?
/sitecore/content/home/clubs//17th//*
- That should get you all children and grandchildren of 17th item (which in turn is a child or grandchild of clubs). If that doesn't work then post up your C# code too. – jammykam