Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Kyle Phillips

    (@kylephillips)

    Here’s an example Gist to get you started if you’re using Gravity Forms:

    https://gist.github.com/kylephillips/e3ff276a0355b2cb5d38

    You’ll need to update the specific form ID and field entry keys to match your form, and edit the notification output for your needs.

    Thread Starter lcsternstrategy

    (@lcsternstrategy)

    Kyle,

    This is working great for me! Thank you so much for the quick responses and I hope this ends up helping a lot of people with a similar request.

    AndrewNYC

    (@andrewnyc)

    Hello, I’ve also tried to implement this but it’s not clear to me how this is done. I’ve added the code to functions.php and changed the form IDs where needed. Then I embedded the form in the actual page where the favorites are output on my site. The email sends but there is no favorites list attached. Thanks for any help…

    Thread Starter lcsternstrategy

    (@lcsternstrategy)

    Andrew,

    I used the code provided by Kyle almost exactly. I don’t think I added code anywhere else to get this working for me. I’m not sure if I could be of much assistance, but an example of the code you’re using may help Kyle troubleshoot the issue.

    AndrewNYC

    (@andrewnyc)

    I also used the code exactly as written, and just filled in the specific form info. The ID# of the email is 5 and the field entries are 2 and 7:

    add_filter( 'gform_notification_5', 'email_favorites_list', 10, 3 );
    function email_favorites_list($notification, $form, $entry)
    {
    	// Get the user's favorites and create a list
    	$favorites = get_user_favorites();
    	if ( !$favorites ) return $notification;
    
    	$fq = new WP_Query(array(
    		'post_type' => 'post',
    		'posts_per_page' => -1,
    		'post__in' => $favorites
    	));
    	if ( $fq->have_posts() ) :
    		// Styles should be set inline for display in email clients
    		$list = '<ul style="list-style-type:none;">';
    		while ( $fq->have_posts() ) : $fq->the_post();
    			$list .= '<li>';
    			if ( has_post_thumbnail() ) $list .= get_the_post_thumbnail(get_the_id());
    			$list .= '<h3>' . get_the_title() . '</h3>';
    			$list .= '<p>' . get_the_excerpt() . '</p>';
    			$list .= '</li>';
    		endwhile;
    		$list .= '</ul>';
    	else :
    		return $notification;
    	endif; wp_reset_postdata();
    
    	// Append the list to the notification message
    	$notification['message'] = $list;
    
    	// Change the to address to the user-specified email (this will change depending on your form)
    	$notification['to'] = $entry[2]; // Email Field
    	$notification['subject'] = __('A Favorites List from', 'textdomain') . ' ' . $entry[7]; // Name Field
    
    	return $notification;
    }

    Kyle, can you possibly provide some input into why this might not be working please?

    I’ve also tried this to no avail – was there a specific way you set up the Gravity form?
    Thanks!

    Thread Starter lcsternstrategy

    (@lcsternstrategy)

    I don’t have any special settings in the form, but I can copy and paste what I have in my theme.

    Here is my page-booksmarks.php:

    <?php get_header(); ?>
    
    <div class="container-wrap">
    
    	<div class="container main-content">
    
    		<div class="row bookmarks">
    				<div class="col span_12 section-title blog-title">
    					<h1>
    						<?php the_title(); ?>
    					</h1>
    
    					<a href="/contact?id=
    					<?php
    					/**
    					* Method 2: WP_Query Object
    					* Check if there are favorites before instantiating the WP_Query.
    					* Passing an empty array as an argument returns ALL posts.
    					* @see https://codex.www.ads-software.com/Class_Reference/WP_Query#Post_.26_Page_Parameters
    					*/
    					$favorites = get_user_favorites();
    					if ( $favorites ) : // This is important: if an empty array is passed into the WP_Query parameters, all posts will be returned
    					$favorites_query = new WP_Query(array(
    						'post_type' => 'speakers', // If you have multiple post types, pass an array
    						'posts_per_page' => -1,
    						'ignore_sticky_posts' => true,
    						'post__in' => $favorites,
    						'paged' => $paged // If you want to include pagination, and have a specific posts_per_page set
    					));
    					if ( $favorites_query->have_posts() ) : while ( $favorites_query->have_posts() ) : $favorites_query->the_post();
    						// Treat this like any other WP loop
    						?>
    
    						<?php the_title(); ?>,
    
    					<?php endwhile;
    					next_posts_link( 'Older Favorites', $favorites_query->max_num_pages );
    					previous_posts_link( 'Newer Favorites' );
    					endif; wp_reset_postdata();
    					else :
    						// No Favorites
    						?>
    						You don't have any bookmarks yet.
    					<?
    					endif; ?>
    					" class="blue-button contact-all"><i class="fa fa-comment fa-2x"></i>Inquire About Bookmarked Speakers</a>
    
    				</div>
    
    				<div class="clear"></div>
    
    			</div>
    
    		<div class="row list">
    
    			<?php
    			/**
    			* Method 2: WP_Query Object
    			* Check if there are favorites before instantiating the WP_Query.
    			* Passing an empty array as an argument returns ALL posts.
    			* @see https://codex.www.ads-software.com/Class_Reference/WP_Query#Post_.26_Page_Parameters
    			*/
    			$favorites = get_user_favorites();
    			if ( $favorites ) : // This is important: if an empty array is passed into the WP_Query parameters, all posts will be returned
    			$favorites_query = new WP_Query(array(
    				'post_type' => 'speakers', // If you have multiple post types, pass an array
    				'posts_per_page' => -1,
    				'ignore_sticky_posts' => true,
    				'post__in' => $favorites,
    				'paged' => $paged // If you want to include pagination, and have a specific posts_per_page set
    			));
    			if ( $favorites_query->have_posts() ) : while ( $favorites_query->have_posts() ) : $favorites_query->the_post();
    				// Treat this like any other WP loop
    				?>
    
    				<div class="bookmark-list">
    		        	<a href="<?php the_permalink(); ?>">
    						<?php the_post_thumbnail('speaker-thumb'); ?>
    					</a>
    
    					<div class="info">
    						<a href="<?php the_permalink(); ?>"><h3><?php the_title(); ?></h3></a>
    						<p><?php the_excerpt(); ?></p>
    						<?php the_favorites_button($post_id, $site_id); ?>
    					</div>
    
    					<div class="clear"></div>
    
    				</div> <!-- end .post-excerpt -->
    
    			<?php endwhile; 
    
    		?> </div> <?php 
    
    			gravity_form( 2, false, false, false, '', true );
    
    			endif; wp_reset_postdata();
    			else :
    				// No Favorites
    				?>
    				You don't have any bookmarks yet.
    			<?
    			endif; ?>
    
    		</div><!--/row-->
    
    	</div><!--/container-->
    
    </div>
    <?php get_footer(); ?>

    functions.php:

    /**
    * Allow a user to email a list of favorites
    * @link https://www.gravityhelp.com/documentation/article/gform_notification/
    */
    add_filter( 'gform_notification_2', 'email_favorites_list', 10, 3 );
    function email_favorites_list($notification, $form, $entry)
    {
      // Get the user's favorites and create a list
      $favorites = get_user_favorites();
      if ( !$favorites ) return $notification;
    
      $fq = new WP_Query(array(
        'post_type' => 'speakers',
        'posts_per_page' => -1,
        'post__in' => $favorites
      ));
      if ( $fq->have_posts() ) :
        // Styles should be set inline for display in email clients
        $list = '<div style="max-width: 550px; margin: 0 auto; padding: 50px 0;">';
        $list .= '<img src="" width="345px" height="113px" style="margin-bottom: 30px;" alt="">';
        $list .= '<p style="font-family: Open Sans, sans-serif; margin-bottom: 50px; line-height: 20px;">Below is your list of bookmarked speakers.</p>';
        while ( $fq->have_posts() ) : $fq->the_post();
          $list .= '<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700" rel="stylesheet" type="text/css">';
          $list .= '<div class="bookmark-list" style="border-bottom: solid 1px rgba(55, 47, 53, 0.3); margin-bottom: 10px; padding-bottom: 10px;">';
          //$list .= '<div class="photo">' . get_the_post_thumbnail(get_the_id()) . '</div>';
          $list .= '<h3 style="font-family: Open Sans, sans-serif; text-transform: uppercase; font-size: 18px; line-height: 28px;">' . get_the_title() . '</h3>';
          $list .= '<p style="font-family: Open Sans, sans-serif;">' . get_the_excerpt() . '</p>';
          $list .= '<a href="' . get_the_permalink() . '" style="font-family: Open Sans, sans-serif; color: #00afbb; padding: 10px 15px; border: solid 1px #00afbb; font-size: 12px; line-height: 12px; display: inline-block; text-decoration: none;">View Speaker</a>';
          $list .= '</div>';
        endwhile;
        $list .= '</div>';
        $list .= '<div class="footer" style="width: 96%; background: #f8f8f8; padding: 20px 2%;">
                  <p style="max-width: 550px; margin: 0 auto; font-family: Open Sans, sans-serif; font-size: 12px; line-height: 18px; text-align: center;">Copyright ? 2015, All rights reserved.?</p>
                  </div>';
      else :
        return $notification;
      endif; wp_reset_postdata();
    
      // Append the list to the notification message
      $notification['message'] = $list;
    
      // Change the to address to the user-specified email (this will change depending on your form)
      $notification['subject'] = __('Your Bookmarked Speakers', 'textdomain'); // Name Field
    
      return $notification;
    }

    Oddly enough, after updating to the latest WP version this suddenly started to work. I would like to send only thumbnail size images (not full size images) and I want to link the title to the page from the favorited item. These two changes should be simple but can’t seem to get it to work…any advice? THanks!

    Hi there,

    After 3 days on this I’m losing the will to live. It would help of course if I had a clue how the code worked!

    I’ve pasted the code Kyle provided in functions.php in my Divi theme child theme file. I created a form in gravity forms and updated the ID and the field IDs in the code. I then placed the gravity form shortcode on my wordpress page to call up the form.

    When I click submit on the form the e-mail I receive just shows the E-mail and Name (in the message body), in a ‘table’, and the subject is ‘New submission from …..’. There’s no list of favourites underneath.

    I’m hopeless at coding and probably way out of my depth. If anyone has the patience to reply, I would be very appreciative.

    Regards,

    Mike

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Email list of favorites’ is closed to new replies.