WordPress.org

Ready to get started?Download WordPress

Forums

Media Categories
[resolved] Default to uncategorized (3 posts)

  1. pimschaaf
    Member
    Posted 1 year ago #

    The native WordPress category feature (for Post/Pages) defaults to setting category as 'uncategorized' when no category is selected. This isn't replicated for media in this plugin.

    I have looked around, but I didn't find a way to get it done.

    Great plugin.
    Thanks in advance.

    http://wordpress.org/extend/plugins/media-categories-2/

  2. pimschaaf
    Member
    Posted 1 year ago #

    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.

  3. pimschaaf
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.