Support » Plugin: Media Categories » Default to uncategorized

Viewing 2 replies - 1 through 2 (of 2 total)
  • I’ve made the following changes to my copy of the plugin, in absence of a filter. All are in media-categories.php

    Added to media_categories_meta_box() (line 140):

    if (!get_the_category($post->ID))
    {
        $selected_cats = array(1);
    } else {
        foreach (get_the_category($post->ID) as $category) {
            $selected_cats[] = $category->cat_ID;
       }
    }

    and added ‘selected_cats’ => $selected_cats to line 176 as follows:

    <?php wp_terms_checklist($post->ID, array('taxonomy' => $taxonomy, 'selected_cats' => $selected_cats, 'popular_cats' => $popular_ids, 'walker' => $custom_walker)) ?>

    This succesfully checks the checkbox for the Uncategorized category, when no other category is selected. However, so far, this is only a visual effect and not saved to the database.

    Instead of my previous code for line 140:

    if (!get_the_category($post->ID))
            {
                wp_set_object_terms($post->ID, 1, 'category');
                $selected_cats = array(1);
            } else {
                foreach (get_the_category($post->ID) as $category) {
                    $selected_cats[] = $category->cat_ID;
                }
            }

    this saves the default category term 1 (Uncategorized) for Uncategorized posts. Do note that this does not support custom taxonomy.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Default to uncategorized’ is closed to new replies.