I've added the functionality to mass unpublish content that came from an api call (roughly 800 entries which are document types with a template under a listing page).
I've been using the UmbracoHelper & ContentService for getting/creating the entries. However, after running the mass unpublish command, I've been left with 800 unpublished entries that I don't want to delete manually.
The UmbracoHelper & ContentService don't seem to work with unpublished content (as they use the IPublishedContent interface), so I'm left trying to figure out how to retrieve the unpublished content. Any ideas?
if (!_examineManager.TryGetIndex(UmbracoIndexes.InternalIndexName, out IIndex index))
And create search query
var searcher = index.Searcher;
var criteria = searcher.CreateQuery(IndexTypes.Content, BooleanOperation.And);
var query= criteria.NodeTypeAlias("MyNodeType");
the field you need query will be isPublished
This link has a code that can help. For your needs, you would change the indexname and make a query for unpublished
Programatically deleting unpublished content
Hi,
I've added the functionality to mass unpublish content that came from an api call (roughly 800 entries which are document types with a template under a listing page).
I've been using the UmbracoHelper & ContentService for getting/creating the entries. However, after running the mass unpublish command, I've been left with 800 unpublished entries that I don't want to delete manually.
The UmbracoHelper & ContentService don't seem to work with unpublished content (as they use the IPublishedContent interface), so I'm left trying to figure out how to retrieve the unpublished content. Any ideas?
Thanks!
Hi Nicolas,
You can do this via Examine and InternalIndex and loop through these unpublished nodes and remove via ContentService.
try use IExamineManager https://docs.umbraco.com/umbraco-cms/reference/searching/examine/examine-manager
Probably inject IExamineManager
try to get index internal
And create search query
the field you need query will be isPublished
This link has a code that can help. For your needs, you would change the indexname and make a query for unpublished
https://www.umbrajobs.com/blog/posts/2021/june/umbraco-9-examine-basic-search/
another article https://www.jondjones.com/learn-umbraco-cms/umbraco-9-tutorials/getting-started-with-umbraco-9/how-to-build-a-search-page-in-umbraco-v9/
Worked like a charm, thanks!
is working on a reply...