+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Filter by Tags in FilterExpression

Filter by Tags in FilterExpression

6 posts, 0 answered
  1. Jackson
    Jackson avatar
    51 posts
    Registered:
    23 May 2008
    27 Oct 2008
    Link to this post
    How can I filter a NewsView List to only show articles tagged with a certain tag.

    I tried this Tag.Name = "Banking & Finance" but it is not showing up any articles that are tagged with this value.

    Please give an example.

    Thanks.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    28 Oct 2008
    Link to this post
    Hello Chris Morrow,


    Here is what you need to do:
    1. Drag and drop NewsView control from the toolbox
    2. Go to advanced tab --> Filters
    3. Use the following FilterExpression
    Publication_Date <= "#now" AND Expiration_Date > "#now" AND Tag.Name = "mytag"


    This applies to Sitefinity version 3.5.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Kieran
    Kieran avatar
    56 posts
    Registered:
    14 Aug 2008
    05 Oct 2010
    Link to this post
    Hi

    I am trying to filter if a tag is not equal.

    Publication_Date <= "#now" AND Expiration_Date > "#now" AND Tag.Name != "mytag"

    What is the correct syntax to achieve this?

    thanks
    Kieran
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    05 Oct 2010
    Link to this post
    Hello Kieran,

    NotEqual operant is not supported by FilterExpression property. You need to create a custom list or override NewsView control if you want to get all items that do not belong to this Tag. Here is a sample code

    var Manager = new ContentManager("News");
    IList TaggedItems = Manager.GetContent(0, 0, string.Empty, "mytag");
    var allItems = Manager.GetContent();
    var queriable = allItems.Cast<IContent>().AsQueryable();
    var result = new List<IContent>().ToList();
    foreach (IContent c in TaggedItems)
    {
        var id = c.ID;
        result = queriable.Distinct().Where(cnt => cnt.ID != id).ToList();
    }


    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Antoniu
    Antoniu avatar
    1 posts
    Registered:
    25 Oct 2010
    10 Dec 2010
    Link to this post
    how can i achieve something like?
    Publication_Date <= "#now" AND Expiration_Date > "#now" AND Tag.Name in ("mytag","mytag2") ?
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Dec 2010
    Link to this post
    Hi Antoniu,

    Filtering by multiple tags is not supported. The condition above will get the latest tag you specify. You can take a look at this forum post to find samples that shows how to do this programmatically.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
6 posts, 0 answered