Where condition for Publish articles

David Pearson asked on May 27, 2016 14:05

I have a web part that list the last 5 news items. I discover today it is listing articles that are not publish yet. What is the Where Condition for checking if an article is publish. maybe: publish = true???

Thanks Dave

Correct Answer

Anton Grekhovodov answered on May 27, 2016 14:53

Hi David,

In where condition you can try to use Published = 1. But it's weird that select only published checkbox doesn't work

1 votesVote for this answer Unmark Correct answer

Recent Answers


Bryan Soltis answered on May 27, 2016 14:12

Are you using a standard Kentico web part (repeater, data source, etc.)? If so, you can check the "Select only published" box in the web part properties.

If you are using a custom control, how are you getting your data? Custom query? Straight SQL?

Also, if you are logged in an editor and viewing the site in "Preview" mode, it will display unpublished items, as well. Be sure to click the "Close preview" link at the top of the page (when viewing the live site).

2 votesVote for this answer Mark as a Correct answer

David Pearson answered on May 27, 2016 14:28

I do have Select Only Published checked. Looking deeper into the issue now.

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on May 27, 2016 18:29

Hi David,

  1. Are you using a repeater to get data directly from a page type? In this case Bryan's solution is correct. OR
  2. Are you using a Datasource to get and connecting it to a repeater? In this case you ave to join your page type over View_CMS_Tree_joined and use clause Where Published =1 to get the data for only published article.

Which way are you using?

Thanks, Chetan

0 votesVote for this answer Mark as a Correct answer

Laura Frese answered on May 27, 2016 18:33 (last edited on December 10, 2019 02:30)

Do you have workflow applied & are you sure the pages are in an unpublished state (what color is the icon next to the page name in the content tree)? If you are just setting the date for a future date then use that for your where condition instead.

(NewsReleaseDate < '{% DateTime.Now |(identity)GlobalAdministrator%}')

0 votesVote for this answer Mark as a Correct answer

David Pearson answered on June 27, 2016 19:38

I was using a basic repeater connected to CMS.News. Publish = 1 fix the issue.

0 votesVote for this answer Mark as a Correct answer

Chidozie Bright answered on January 30, 2018 02:09

I am having an issue with this as well. I've created a new page type that includes the publish to and from fields. I can save the publish from date however it is not being filtered out. When I look at the field in the database is says it is NULL, however the value is still loaded when I open the Form tab for the page.

1 votesVote for this answer Mark as a Correct answer

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