Fetching Custom Tags

Latch's form editor includes a Tags datatype powered by the Tagify vendor library.

Tags are used in several default forms. For example, pages can have Categories.

To check whether a post has a category:

<?php

if ($_SESSION["latch"]->db->has_tag("post", $post_id, "Categories", $category))
{
    echo "This post has category " . \Latch\Input\sanitize("html", $category);
}

The first argument, $context, tells Latch which database table to inspect.

Supported contexts include:

  • post: Checks latch_posts.
  • field: Checks form fields in latch_forms.
  • group, role, or parent: Checks latch_parents.

When checking parent metadata fields other than the default tags field, pass the metadata field name as the third argument and the tag value as the fourth argument:

<?php

$can_read = $_SESSION["latch"]->db->has_tag("group", $form_id, "read-permissions", "Administrator");