• jclarke607

    (@jclarke607)


    Hi all,

    Hope this the right place for this question.

    I’m making a site for a journalist to showcase her work. It will feature online examples of her work,and print examples.

    I’ve made two plugins which I’ve placed in the mu-plugins folder. Their purpose is to make two new custom post types. One is called “online” and the other “print”. The plugins also automatically assign a category of the same name to each of the post types. So, “online” are automatically marked as “online” and “print” is marked with the “print” category.

    However, there seems to be some sort of conflict, as if I run both plugins, all posts, regardless of the custom post type being used, revert to being put in the “online” category. If I remove the “online” custom post plugin, things revert to “print” as I would want so I’m assuming there is a conflict.

    Here’s my code for the “online” post type’s auto-category part at the bottom of the file….

    // Automatically assign online category.
    // (Only if no other category has been manually specified)
    
    	function add_ion_online_post_category_automatically($post_ID) {
    	global $wpdb;
    	if(!has_term('','category',$post_ID)){
    	$iononlinepostcat = online;
    	wp_set_object_terms($post_ID, $iononlinepostcat, 'category');
    	}
    }
    
    // Save online post
    add_action('save_post', 'add_ion_online_post_category_automatically');
    add_action('save_post', 'ion_save_online_posts_meta', 1, 2);

    And here’s the code for my “print” auto category/saving…

    // Automatically assign print category.
    // (Only if no other category has been manually specified)
    
    	function add_ion_print_post_category_automatically($post_ID) {
    	global $wpdb;
    	if(!has_term('','category',$post_ID)){
    	$ionprintpostcat = "print";
    	wp_set_object_terms($post_ID, $ionprintpostcat, 'category');
    	}
    }
    
    // Save print post
    add_action('save_post', 'add_ion_print_post_category_automatically');
    add_action('save_post', 'ion_save_print_posts_meta', 1, 2);

    Any help or ideas as to what’s going wrong would be appreciated! I can provide more code if required.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jclarke607

    (@jclarke607)

    Incidentally, I’ve tried simply putting the entire code of both plugins combined into the normal functions file of my theme, but it made no difference.

    Cheers!

    Thread Starter jclarke607

    (@jclarke607)

    Well, I figured it out and thought I’d post just in case anyone had the same problem…

    Turns out that this…

    // Save print post
    add_action('save_post', 'add_ion_print_post_category_automatically');
    add_action('save_post', 'ion_save_print_posts_meta', 1, 2);

    Should have been this…

    // Save print post
    add_action('publish_ion_print_post', 'add_ion_print_post_category_automatically');
    add_action('publish_ion_print_post', 'ion_save_print_posts_meta', 1, 2);

    That is to say that the structure is add_action(‘publish_your-custom-post-type’

    I thought you HAD to use “save_post” or “publish_post” but turns out I needed to add my custom post type name in there too. Silly me.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Automatic category conflict problems’ is closed to new replies.