\Groundhogg\Tag

📅 Published on

📝 Last updated

Documentation

»

Classes

»

\Groundhogg\Tag

extends Base_Object

Represents a contact tag used for segmentation. Tags are applied to contacts to group and filter them for funnels, broadcasts, and reports. Instantiate with a tag ID, name, or slug.

Methods

MethodReturnsDescription
get_id()intReturns the tag ID.
get_name()stringReturns the tag’s display name.
get_slug()stringReturns the tag’s URL-friendly slug.
get_description()stringReturns the tag’s description.
get_contact_count()intReturns the number of contacts currently holding this tag.
get_contact_ids()int[]Returns an array of contact IDs for all contacts with this tag.
is_preference_tag()boolReturns true if this tag is used as a marketing preference option on the preferences page.
exists()boolReturns true if the tag exists in the database.

Usage

Here’s a pseudo code example for a hypothetical tag-based segmentation report.

<?php

add_action( 'groundhogg/admin/report/lead_score', 'my_plugin_tag_breakdown_report' );

/**
 * Show a breakdown of contacts per tag in the lead score report.
 *
 * @return void
 */
function my_plugin_tag_breakdown_report() {

    $tag_ids = [ MY_PLUGIN_VIP_TAG_ID, MY_PLUGIN_CUSTOMER_TAG_ID, MY_PLUGIN_LEAD_TAG_ID ];

    echo 'Contact counts by tag';

    foreach ( $tag_ids as $id ) {
        $tag = new \Groundhogg\Tag( $id );

        if ( ! $tag->exists() ) {
            continue;
        }

        echo '' . esc_html( $tag->get_name() ) . ': ' . $tag->get_contact_count() . '';
    }

    echo '';
}

Was this helpful?

Let us know if this document answered your question. That’s the only way we can improve.