Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm currently displaying custom taxonomies in a drop down menu. Each taxonomy has its own little wrapper in the sidebar. Is it possible to move the taxonomy to inside of my custom write box for ease-of-use purposes?

enter image description here

share|improve this question
    
Take a look at this solution wordpress.stackexchange.com/questions/21275/… –  Bainternet Jun 29 '11 at 19:10
add comment

2 Answers

up vote 5 down vote accepted

The following is taken from a "move author to publish box" task, but it should give you a starting point. Next you should take a look at "/wp-admin/edit-form-advanced.php" where you'll find something about get_object_taxonomies() to see how your stuff get's named, so you can remove and add stuff.

function wpse_remove_author_box() 
{
    if ( ! is_admin() )
        return;

    remove_meta_box( 'authordiv', 'post', 'normal' ); 
}
add_action( 'admin_menu', 'wpse_remove_author_box' );

function wpse_author_to_publish_box() 
{
    if ( ! is_admin() )
        return;

    global $post_ID;
    $post = get_post( $post_ID );
        ?>
        <div id="author" class="misc-pub-section" style="border-top-style:solid; border-top-width:1px; border-top-color:#EEEEEE; border-bottom-width:0px;">
            Author: 
            <?php post_author_meta_box( $post ); ?>
        </div>
        <?php 
}
add_action( 'post_submitbox_misc_actions', 'wpse_author_to_publish_box' );
share|improve this answer
    
Thanks for the starting point @Kaiser! –  mattrepublic Jun 29 '11 at 18:09
    
@M.Taylor You're welcome :) –  kaiser Jun 29 '11 at 18:10
add comment

I was able to achieve this with custom taxonomies on a metabox I created for a custom post type of mine by doing the following:

First I added this to my functions.php:

add_action( 'admin_menu', 'remove_default_metaboxes' );
function remove_default_metaboxes() {
    // Remove 'Keywords' (like tags) metabox
    remove_meta_box( 'tagsdiv-keyword', 'my-custom-post-type-slug', 'side' );
    // Remove 'Groups' (like categories) metabox
    remove_meta_box( 'groupdiv', 'my-custom-post-type-slug', 'side' );
}

The first parameter of the function remove_meta_box() is actually an id generated by WordPress. If you are using non-hierarchical taxonomies (i.e. "Tags"), it will always be "tagsdiv-" followed by your custom taxonomy slug. If it's a hierarchical taxonomy (i.e. "Category") the id will be the slug followed by "div", no spaces.

I then put the following code on my metabox template:

<div class="groups">
<?php
    $box = array(
        'args' => array(
            'taxonomy' => 'group'
        ),
        'title' => 'Groups'
    );
    post_categories_meta_box($post, $box)
    ?>
</div>

<div class="keywords inside">
    <?php
        global $post_ID;
        $post = get_post( $post_ID );
        $box = array(
            'args' => array(
                'taxonomy' => 'keyword'
            )
        );
        post_tags_meta_box($post, $box);
    ?>
</div>

Finally, note that in the case of "Keywords" or any other Tag-like taxonomy, this will not be enough. The tags metabox functionality is achieved via JS, which depends on selectors that are not created by the function above. In my case this was solved by adding the class "inside" to the keywords div, and by adding these lines to a separate JS file:

$('.keywords').each(function(){
    tagBox.init();
    return false;
}); 

Just make sure to call the JS after WP has loaded the default Post scripts. If for some reason you don't want to add more scripts, you can achieve the same by mimicking WP's structure like so:

<div id="side-sortables">
   <div id="tagsdiv-keyword" class="postbox inside">
       // post_tags_meta_box() etc
   </div>
</div>
share|improve this answer
    
Thanks Tomas, I can't wait to try this out –  mattrepublic Jul 6 '11 at 2:47
    
You're welcome. I've edited the original answer to include the "inside" class to one of the divs. Without it the tag cloud would display correctly, but the links did not have the expected effect. Again, it's a matter of the selectors used by WP on its post.js file. –  tbuteler Jul 6 '11 at 4:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.