WordPress.org

Ready to get started?Download WordPress

Forums

Postie
[resolved] Custom post type with two Custom Taxonomies (4 posts)

  1. mjpg
    Member
    Posted 1 year ago #

    Using Postie v1.5.15.

    I have a custom post type that has two Custom Taxonomies.

    Is it possible to get Postie to recognise the category/taxnomy using the default settings ie:

    [bbs] This is another title
    or
    tags:26 This is the title

    I cannot get this to work.

    If this does not work, is it going to be possible to do this with a filter using the v1.5.15 syntax - eg:

    add_filter('postie_post_before',...

    If so, could someone give a pointer to the best approach please?

    http://wordpress.org/plugins/postie/

  2. mjpg
    Member
    Posted 1 year ago #

    I managed to work out the following code that seems to work OK.

    I have two custom taxonomies - region and type.

    // Categories are specified in the subject using:  [category1] [category2] title - this is used for type
    // tags in the body using:  tag:tag1, tag2 - these are used for region
    
    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_postie_post_function($post) {
    
    	// Check for categories and use in type
    	check_post_set_taxonomy($post,'post_category','type');
    
    	// Check for tags and use to set region
    	check_post_set_taxonomy($post,'tags_input','region');
    
    	return $post;
    }
    
    add_filter('postie_post_before', 'add_custom_taxonomy_postie_post_function');

    Is there a better way - improvements?

    Thanks

  3. Wayne Allen
    Member
    Plugin Author

    Posted 1 year ago #

    That looks good to me.

  4. mjpg
    Member
    Posted 1 year ago #

    Thanks for checking.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic