Add custom post type to %title% of emails sent via Subscribe by Email

I'm trying to edit the files to allow the following.

I have a few different custom post types that I want to send emails to subscribers once someone post in the categories. For example, we have "Galleries" and "Notices". I want the title of the email and title of the "body" of the email to be "Blog Name : post_type" So the output would be "City of Hanahan : Notices" and then display the notice. Or "City of Hanahan : Gallery" and then display the gallery.

I hope that makes sense.

  • Luís
    • Support

    Hi David ,

    Hope you're doing well today!

    If I understood well your question, please try this:

    1) Using FTP access, go to "wp-content/plugins/subscribe-by-email/inc/mail-templates/views/" folder and download "post.php" file;

    2) Then add this code where you want to display it:

    <h2>
    	<?php 
    
    		//add the blog/sitename
    
    		if ( sbe_display_blog_name() ):
    			echo sbe_get_from_sender();
    
    		endif;
    
    	?>
    
    	:
    
    	<?php
    
    		//add the post type name
    
    		$post_type=get_post_type();
    
    		echo $post_type; 
    
    	?>
    
    </h2>

    3) Inside of your root theme folder create another folder called "subscribe-by-email" and upload the file to inside of it, in order to override the original template file.

    I hope this information has been helpful. If I can help you in this or other questions, please let me know!

    Cheers, Luís

  • David
    • The Crimson Coder

    Hello Luis,
    That worked, however I have a question.

    It's displaying as "lsvrevent" after the title. That is the official name of the custom_post_type created by the theme. Anyway to change that to just "Event" or possibly mask the lsvrevent tag?

    Thank you for the help!

  • Luís
    • Support

    Hi David ,

    Hope you're doing well today!

    I think we can mask the custom post type name, try change the code given to:

    <h2>
    	<?php 
    
    		//add the blog/sitename
    		if ( sbe_display_blog_name() ):
    			echo sbe_get_from_sender();
    		endif;
    	?>
    	:
    	<?php 
    
    		//add the post type name
    		$post_type=get_post_type();
    
    		//if is "lsvrevent" post type change the name displayed
    		if ($post_type == "lsvrevent")
    		{
    			echo "Events";
    		}
    		else {
    		echo $post_type;
    		}
    	?>
    
    </h2>

    I hope this information has been helpful. If I can help you in this or other questions, please let me know!

    Cheers, Luís

  • David
    • The Crimson Coder

    Luís LUIS!!!! That worked. Outstanding. Now, I have a quick question in addition to that but along the same lines.

    I need to mask a few different custom_post_types. How would I go about adding one for Notices and Galleries as well?

    Thanks,
    David

  • David
    • The Crimson Coder

    Luís

    This is what I have come up with, if you could verify.

    <?php 
    
    		//add the blog/sitename
    		if ( sbe_display_blog_name() ):
    			echo sbe_get_from_sender();
    		endif;
    	?>
    
    	<?php 
    
    		//add the post type name
    		$post_type=get_post_type();
    
    		//if is "lsvrevent" post type change the name displayed
    		if ($post_type == "lsvrevent")
    		{
    			echo "Events";
    		}
    		//if is "lsvrgallery" post type
    		if ($post_type == "lsvrgallery")
    		{
    			echo "Gallery";
    		}
    		//if is "lsvrnotice" post type
    		if ($post_type == "lsvrnotice")
    		{
    			echo "Notice";
    		}
    		else {
    		echo $post_type;
    		}
    	?>
  • Luís
    • Support

    Hi David ,

    Hope you're doing well today!

    Your code should work, however, in order to be more "efficient" I would suggest to change the last part (related to the custom post type) to:

    <?php 
    
    		//add the post type name
    		$post_type=get_post_type();
    
    		switch ($post_type){
    
    			case "lsvrevent":
    
    				echo "Events";
    				break;
    
    			case "lsvrgallery":
    
    				echo "Gallery";
    				break;
    
    			case "lsvrnotice":
    
    				echo "Notice";
    				break;
    
    			default:
           			echo $post_type;
    
    		}
    
    	?>

    I tested this code in my install so it should work in yours too, however, try it and let me know!

    Cheers, Luís

  • Luís
    • Support

    Hi David ,

    Hope you're doing well today!

    There are several methods, print to screen, print to the debug log:

    http://stackoverflow.com/questions/6079492/how-to-print-a-debug-log

    However, my PHP skills are basic, so, I created a shortcode to show all the Post Types. Add this code to your theme functions.php:

    function myCustomPostTypes(){
    
    $post_types = get_post_types( );
    
        echo '<ul>' ;
        foreach ( $post_types  as $post_type ) {
    
            echo '<li>' .$post_type .'</li>' ; 
    
        }
        echo '</ul>' ;
    }
    
    add_shortcode('list_post_types', 'myCustomPostTypes' );

    Then, create a page and add the following shortcode to the content:

    [list_post_types]

    I hope this information has been helpful. If I can help you in this or other questions, please let me know!

    Cheers, Luís

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.