WordPress.org

Ready to get started?Download WordPress

Forums

Post Expirator
Can't get custom taxonomies working (7 posts)

  1. xavierverhoeven
    Member
    Posted 2 years ago #

    I'm trying to set up Post Expirator with a custom post type, which works well for setting to draft. But I'm hoping to set it to change categories instead.

    I've got a custom taxonomy set up for 'locations_category', and have tried to hack this into the plugin myself. It all looks like it will work in the backend (the locations categories are showing up for me), but the actual change doesn't occur. I'm guessing I haven't quite made all the changes I need to the plugin.

    It's a great plugin, and will be perfect for my needs with this one tweak - can anyone help me out?

    Thanks,
    Xavier

    http://wordpress.org/extend/plugins/post-expirator/

  2. Aaron Axelsen
    Member
    Plugin Author

    Posted 2 years ago #

    If you can provide a link to the code I can take a look and see - feel free to just dump it into pastebin.com

  3. xavierverhoeven
    Member
    Posted 2 years ago #

    Hi Aaron,

    Thanks for the reply.

    I've pasted the code here: http://pastebin.com/n945cq4y

    I've changed a few instances of category to locations_category, but think the problem likely lies with this section, as I'm not sure how to edit it for custom taxonomies:

    `// Check to see if expiration category is enabled and set - otherwise, proceed as normal
    $catEnabled = get_option('expirationdateCategory');
    $cat = get_post_meta($a->post_id,'_expiration-date-category');
    if (($catEnabled === false || $catEnabled == 1) && (isset($cat) && !empty($cat[0]))) {
    wp_update_post(array('ID' => $a->post_id, 'post_category' => $cat[0]));`

    Any help with be much appreciated!

  4. rellison959
    Member
    Posted 2 years ago #

    ANY luck with this? I am in the same situation. I use the PE on a custom post type and need to have it move those 'posts' to a different category, but the cats for the CPTs do not show in the Post Exp. settings.

    PLEASE help!

  5. rellison959
    Member
    Posted 2 years ago #

    Just found this to add standard post type categories to custom post types.

    add_action( 'init', 'wpse6098_init', 100 ); // 100 so the post type has been registered
    function wpse6098_init()
    {
        register_taxonomy_for_object_type( 'category', 'your_custom_post_type' );
    }
  6. Aaron Axelsen
    Member
    Plugin Author

    Posted 2 years ago #

    There are 3 areas of code that you will need to change if you wish to use a custom taxonomy instead of the default category:.

    In the examples below I will use 'mycat' as the slug for my custom taxonomy.

    In the "expirationdate_delete_expired_posts" function find

    wp_update_post(array('ID' => $a->post_id, 'post_category' => $cat[0]));

    and replace with

    $terms = array_map('intval', $cat[0]);
    wp_set_object_terms($a->post_id,$terms,'mycat',false);

    In the "expirationdate_meta_box" function find

    wp_terms_checklist(0, array( 'taxonomy' => 'category', 'walker' => $walker, 'selected_cats' => $categories, 'checked_ontop' => false ) );

    and replace it with

    wp_terms_checklist(0, array( 'taxonomy' => 'mycat', 'walker' => $walker, 'selected_cats' => $categories, 'checked_ontop' => false ) );

    In the "postExpiratorMenuGeneral" function find

    wp_terms_checklist(0, array( 'taxonomy' => 'category', 'walker' => $walker, 'selected_cats' => $categories, 'checked_ontop' => false ) );

    and replace it with

    wp_terms_checklist(0, array( 'taxonomy' => 'mycat', 'walker' => $walker, 'selected_cats' => $categories, 'checked_ontop' => false ) );

    That should do the trick - or at least it did for me in my testing on 3.3.2

  7. disawish
    Member
    Posted 1 year ago #

    Thank You very very much !!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic