WordPress.org

Forums

Postie
[resolved] Support for custom taxonomy in subject line? (16 posts)

  1. cfink381
    Member
    Posted 1 year ago #

    I'm considering adding a custom taxonomy or two to my site, but I don't want to break my existing workflow with Postie. Does Postie support the setting of custom taxonomies in the subject line?

    For example, my site deals with books and each post has a category for "age group" (Children's, Middle Grade, Young Adult, etc.) and a category for "genre" (Mystery, Thriller, Sci-Fi, etc.). Right now these are both set as categories, and I'm sending them in with a subject line like:

    [Young Adult] [Sci-Fi] Awesome Book by Joe Author

    This setup works great. But I'd like to expand my users' ability to search for books, and setting up a new taxonomy of "age group" and "genre" seems to make sense. So I'd love to be able to send in a subject line like:

    [Age Group: Young Adult] [Genre: Sci-Fi] Awesome Book by Joe Author]

    Is this possible?

    Thank you!

    https://wordpress.org/plugins/postie/

  2. Wayne Allen
    Member
    Plugin Author

    Posted 1 year ago #

    Postie will recognize any term in the WordPress taxonomy, however, you can't restrict it like your example.

    Postie will match the terms against any taxonomy and there isn't an guarantee which will be used if you have duplicates. I.e. category sci-fi and genre sci-fi.

  3. cfink381
    Member
    Posted 1 year ago #

    Excellent! Thanks for the quick response. I'll move forward by creating the custom taxonomies and making sure there are no duplicates between them and the categories. Thank you!

  4. cfink381
    Member
    Posted 1 year ago #

    Just ran a few tests through and Postie is correctly picking up the IDs for the custom taxonomies (which I can see in the debug output), but they're not being applied to the post.

    The end of the debug output shows:
    ...
    Post Author: 1
    Date: 2014-01-27 17:00:00
    Category: 10
    Category: 15
    Category: 6
    ...

    ID 10 is Fiction in the Genre taxonomy
    ID 15 is Sci-Fi in the Genre taxonomy
    ID 6 is Young Adult in the Age Group taxonomy

    All these are correct, based on my subject line:
    [Fiction] [Sci-Fi] [Young Adult] Awesome Book by Joe Author

    Is Postie trying to apply the IDs as taxonomy = category, and therefore not applying them correctly since the IDs relate to taxonomies other than category? Any recommendations on how to set the taxes correctly?

    Thank you!

  5. Wayne Allen
    Member
    Plugin Author

    Posted 1 year ago #

    I'll need to look into this a bit more. I've done this exact thing in the past, but maybe WordPress 3.9 is more picky.

  6. Wayne Allen
    Member
    Plugin Author

    Posted 1 year ago #

    Just to make sure we're looking at the same thing, how did you create the taxonomy? Did you use a plugin?

  7. cfink381
    Member
    Posted 1 year ago #

    I used Themergency's code generator (http://themergency.com/generators/wordpress-custom-taxonomy/) and pasted the code in my theme's functions.php file. I used all the default values except for setting rewrite to false.

    Thanks for looking in to this!

  8. Wayne Allen
    Member
    Plugin Author

    Posted 12 months ago #

    Postie will only choose a taxonomy if you have "Match short category" set to yes.

  9. cfink381
    Member
    Posted 11 months ago #

    Just ran some more tests through and I'm still getting the same result: Postie is identifying the correct custom taxonomy IDs, but they are not being applied to the post.

    I've updated WordPress to 3.9.1, deactivated, removed and reinstalled the latest version of Postie and deactivated all other plugins. "Match short category" is set to Yes.

    Here's the section of the debug output where Postie is identifying the categories via the wildcard:

    tag_Categories: found categories
    Array
    (
        [0] => Array
            (
                [0] => Array
                    (
                        [0] => [Fiction]
                        [1] => [Action and Adventure]
                        [2] => [Everything else]
                        [3] => [Image and Text]
                    )
    
                [1] => Array
                    (
                        [0] => Fiction
                        [1] => Action and Adventure
                        [2] => Everything else
                        [3] => Image and Text
                    )
            )
    )
    
    lookup_category: Fiction
    category: found by name Fiction
    stdClass Object
    (
        [term_id] => 10
        [name] => Fiction
        [slug] => fiction
        [term_group] => 0
        [term_taxonomy_id] => 31
        [taxonomy] => category
        [description] =>
        [parent] => 0
        [count] => 0
        [filter] => raw
    )
    
    lookup_category: Action and Adventure
    category wildcard lookup: Action and Adventure
    category wildcard found: 12
    lookup_category: Everything else
    category wildcard lookup: Everything else
    category wildcard found: 9
    lookup_category: Image and Text
    category wildcard lookup: Image and Text
    category wildcard found: 23

    "Fiction" is the only Category, "Action and Adventure" is the Genre taxonomy; "Everything else" is the Age Group taxonomy, and "Image and Text" is the Style taxonomy. The "Fiction" category is successfully applied to the post, but the others are not.

    Any thoughts on how to fix? Do I need a custom filter?

    Thank you!

  10. Wayne Allen
    Member
    Plugin Author

    Posted 11 months ago #

    Odd that it is not working for you. When I test it the custom taxonomies are applied.

    You could write a Postie AddOn to specifically update the taxonomy.

    http://postieplugin.com/extending/

  11. cfink381
    Member
    Posted 11 months ago #

    Not sure why the custom taxonomies weren't working for me, but I was able to get it working with a Postie AddOn, as recommended. Thank you!

  12. Wayne Allen
    Member
    Plugin Author

    Posted 11 months ago #

    Thanks for the update.

  13. jenkma02
    Member
    Posted 5 months ago #

    @cfink381, Any way you could post a code sample with your solution? I'm trying to accomplish the same thing, but I'm kind of stuck. Thanks!

  14. cfink381
    Member
    Posted 5 months ago #

    @jenkma02: Sure thing!

    <?php
    /*
    	Add code set custom taxonomies to the post
    */
    	function check_post_set_taxonomy($post,$post_part_to_check,$taxonomy_name) {
    			foreach ($post[$post_part_to_check] as $key=>$cat_or_tag) {
    			if (term_exists($cat_or_tag, $taxonomy_name)) {
    				wp_set_object_terms( $post['ID'], $cat_or_tag, $taxonomy_name, true );
    				unset($post[$post_part_to_check][$key]);
    			}
    		}
    	}
    	function add_custom_taxonomy_to_post($post) {
    		// Check for categories and use in type
    		check_post_set_taxonomy($post,'post_category','taxonomy1');
    		check_post_set_taxonomy($post,'post_category','taxonomy2');
    		check_post_set_taxonomy($post,'post_category','taxonomy3');
    		check_post_set_taxonomy($post,'tags_input','taxonomy4');
    		return $post;
    	}
    	add_filter('postie_post_before', 'add_custom_taxonomy_to_post');
    /*
    	End code set custom taxonomies to the post
    */
    ?>

    Just replace taxonomy1, taxonomy2, taxonomy3 & taxonomy4 with your taxonomy names and it should work.

    Hope this helps!

  15. cfink381
    Member
    Posted 5 months ago #

    Forgot to mention that the code above is the contents of filterPostie.php. Details here: http://postieplugin.com/extending/

  16. jenkma02
    Member
    Posted 5 months ago #

    Awesome, thanks so much!!!

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Postie
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic