Support » Plugin: wpMandrill » FYI: Example for using merge tags

  • For anyone interested, here is a rudimentary example of one way to structure your call to wpMandrill in order to use merge tags in Mandrill/MailChimp templates.

    Let’s say you have the merge tags *|firstname|*, *|lastname|*, and *|activationkey|* in your email template. Now you want to populate those tags with variables from WordPress. You need to pay attention to the structure of the $global_merge_vars and $merge_vars arrays. Here is an example with the merge vars set for one recipient. For multiple recipients, you’ll have to set up a loop of some sort to pre-populate your global_merge_vars and merge_vars arrays with the values for each recipient :

       $html = '',
       $headers = '',
       $attachments = '',
       $tags = array( 'mytag' ),
       $template_name = 'mytemplate',
       $track_opens = TRUE,
       $track_clicks = TRUE,
       $url_strip_qs = TRUE,
       $merge = TRUE,
       $global_merge_vars = array(),
       $merge_vars = array( array(
          'rcpt' => $to,
          'vars' => array(
             array( 'name' => 'firstname', 'content' => $firstname ),
             array( 'name' => 'lastname', 'content' => $lastname ),
             array( 'name' => 'activationkey', 'content' => $activationkey )

    MC_Will: Great plugin. The documentation and comments in the source could be more clear regarding the structure of some of the expected arrays. It took looking at the API and the JSON string format to realize that the merge arrays, for example, aren’t a simple one-dimensional array.

  • The topic ‘FYI: Example for using merge tags’ is closed to new replies.