簡體   English   中英

Sitecore Powershell通過下拉鏈接字段進行搜索/過濾

[英]Sitecore Powershell search/filter by a droplink field

在Sitecore內容樹中,我列出了約3000篇文章。 每篇文章都有一個作者字段。 作者字段的類型為droplink。 我正在嘗試編寫一個PowerShell腳本,該腳本可以讓我了解每個作者寫的文章數。

#This is where all the Authors lives
cd 'master:/sitecore/content/mysite/Global/Authors Folder'

#Get all the articles that each author has written
function ProcessItem($item) 
{
$articles = Get-Item master: -Query "/sitecore/content/mySite/Home/Articles/2017//*[@@templatename='Article' and @Author='$item.Id']"
$articles.Count
}

#Get a list of authors
$itemsToProcess = Get-ChildItem -Recurse . | Where-Object { $_.TemplateName -match "Authors"  }
if($itemsToProcess -ne $null)
{
   $itemsToProcess | foreach {ProcessItem($_)}
}

看來由作者ID來獲取文章的調用未返回任何內容。 因此, $articles.Count始終返回0。我嘗試使用@Author.Value='$item.Id'但仍未得到任何結果。 有人能看到我在這里做錯什么嗎?

除非針對單個屬性進行測試,否則需要將條件包裝在方括號中,如下所示:

$articles = Get-Item master: `
    -Query "/sitecore/content/mySite/Home/Articles/2017//*[@@templatename='Article' and @Author='$($item.Id)']"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM