admin_url( 'admin-ajax.php' ) ) ); } function cpr_box() { add_meta_box( 'post-meta-boxes', 'Custom Post Relationships (CPR)', 'cpr_category_selector', 'post', 'normal','high' ); } function cpr_category_selector() { global $post_ID; echo "
"; echo " posts from "; wp_dropdown_categories('hide_empty=0&hierarchical=1&name=cpr_filters&show_count=1&show_option_all=All categories'); echo " ordered by in "; echo " order  "; echo " "; echo "   Filter results: "; echo "
"; echo '

Available Posts

Please select a category

Related Posts (Drag to reorder)

"; } // Where's Dukey? Wa zaaaaaaaaaaaa (the call) function cpr_cats() { $catID = $_POST['catID']; $postID = $_POST['postID']; $howMany = $_POST['howMany']; $orderBy = $_POST['orderBy']; $orderIn = $_POST['orderIn']; if ($catID >= 0) { // if all categories selected if ($catID == 0) { $args = array( 'post_type' => 'post', 'numberposts' => $howMany, 'post_status' => 'publish', 'orderby' => $orderBy, 'order' => $orderIn, 'post__not_in' => array($postID) ); $catPosts = get_posts($args); } else { $args = array( 'post_type' => 'post', 'numberposts' => $howMany, 'post_status' => 'publish', 'orderby' => $orderBy, 'order' => $orderIn, 'category__in' => array($catID), 'post__not_in' => array($postID) ); $catPosts = get_posts($args); } if (!empty($catPosts)) { foreach ( $catPosts as $catPost ) { setup_postdata($post); echo "
Add

" . $catPost->post_title . "

"; }// foreach }// if !empty else { echo "
This category is empty
"; } }//if else { echo "
Please select a category
"; } exit; }// function cpr_cats function cpr_save() { global $post_ID; if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id; if (!wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename(__FILE__))) return $post_id; if (!current_user_can( 'edit_post', $post_id ) ) return $post_id; $id = $_POST['post_ID']; $related = $_POST['reladded']; update_post_meta($id, 'cpr_related', $related); } function cpr_populate($id) { global $wpdb; $related_meta = get_post_meta($id, 'cpr_related', true); $related_posts = array(); if (!empty($related_meta)) { foreach ($related_meta as $related) { $post = get_post($related); $related_posts[] = $post; } return $related_posts; } } // oi! wait! where are you going? are you sure? 100%? a second thought? come on let's talk about it. oh well. function cpr_uninstall() { global $wpdb; $wpdb->query($wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_key = 'cpr_related'")); } add_action('admin_menu', 'cpr_box'); add_action('wp_ajax_cpr-cats', 'cpr_cats'); add_action('admin_menu', 'cpr_scripts_styles'); add_action('save_post', 'cpr_save'); add_action('wt4_show','cpr_populate'); register_uninstall_hook(__FILE__, 'cpr_uninstall'); ?>