• Resolved taulal

    (@taulal)


    Hey @kubitomakita,

    I am having a small issue when trying to add a merge tag to an existing trigger.

    The trigger is the post published trigger that gets fired on a custom post type being published.

    The trigger is working fine and the email is being sent correctly, however, I want to add in two custom field’s meta. I am getting the following error:

    Notice: Undefined property: BracketSpace\Notification\Defaults\Trigger\Post\PostPublished::$post

    The error is being generated when I use your example code:

    // Pay attention to the Tag type you are defining.
    	// If you want to output an HTML, use HtmlTag instead.
    	$trigger->add_merge_tag( new BracketSpace\Notification\Defaults\MergeTag\StringTag( [
    		'slug'     => 'new_merge_tag',
    		'name'     => __( 'New Merge Tag', 'textdomain' ),
    		'resolver' => function( $trigger ) {
    			return get_post_meta( $trigger->post->ID, '_my_meta_key', true );
    		},
    	] ) );

    I am creating the merge tags below where “memorial” is my custom post type slug.

    if ( 'post/memorial/published' !== $trigger->get_slug() ) {
    		return;
    	}

    Thanks again,

    Taylor

Viewing 1 replies (of 1 total)
  • Plugin Author Kuba Mikita

    (@kubitomakita)

    Hi Taylor, it’s correct. The post property has a name of the post type slug, in your case it would be memorial.

    So you could change the resolver return statement to:

    
    return get_post_meta( $trigger->memorial->ID, '_my_meta_key', true );
    

    or a dynamic property

    
    return get_post_meta( $trigger->{ $trigger->get_post_type() }->ID, '_my_meta_key', true );
    
Viewing 1 replies (of 1 total)

The topic ‘Undefined variable trigger->post in merge tag’ is closed to new replies.