Bug: WebPageRelatedItem ordering not preserved when using Content Item API with linked items

2026/01/20 7:33 AM

When retrieving a page using the Content Item API with ContentItemQueryBuilder and loading related pages via WithLinkedItems(), the order of related items does not match the order defined in the CMS UI (drag & drop order in relationship field).

The returned related items appear unordered (likely DB join order), and there is no exposed API to access relationship ordering metadata.

here is snap-shot of content saved in db

here the result what I am getting

  var builder = new ContentItemQueryBuilder()
  .ForContentType(ProductCategory.CONTENT_TYPE_NAME, config =>
  config.ForWebsite(_channelContext.GetWebsiteChannelName())
  .Where(where => where.WhereEquals(nameof(WebPageFields.WebPageItemID), context.WebPage.WebPageItemID))
  .WithLinkedItems(100, o => o.IncludeWebPageData())
  );
  var Result = await _contentQueryExecutor.GetMappedWebPageResult<ProductCategory>(builder);
  var page= Result.FirstOrDefault();

Environment

  • Xperience by Kentico version: [30.8.1]

  • .NET version: [8]

  • Execution environment: [Local Dev ]

What is the recommended or supported approach in Xperience by Kentico to retrieve related items in the same order as defined in the CMS UI?

Tags:
Kentico Kentico Community Portal Kentico Connection v30.8.0

Answers

2026/01/20 7:17 PM

I haven't tested this exact scenario to know what might be causing the issue here, but I did recently address a related question.

My recommendation there was to use the IContentRetriever API because it's designed to handle these types of queries and significantly simplify the content querying code.

Additionally, .ForContentType() is the original ContentItemQueryBuilder API that shipped with Xperience by Kentico.

It's replacement, .ForContentTypes(), was added back in March 2024.

My recommendation:

  • First try using IContentRetriever

  • If that doesn't get the result you want, try .ForContentTypes() instead of .ForContentType().

  • If you still get the same result, report a bug to support using a reproduction of the issue in Dancing Goat.

To response this discussion, you have to login first.