Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Sort Posts
- Description: Allows for the reordering of posts
- */
- //actions
- //add buttton to dashboard
- add_action('admin_menu','add_sort_post_button');
- //add meta box
- add_action('admin_init','add_painting_meta_box');
- //add button to plugins menu
- function add_sort_post_button(){
- add_submenu_page('plugins.php', 'Sort Posts', 'Sort Posts', 'manage_options', 'sort-posts','sort_posts_admin');
- }
- //add_meta box
- function add_painting_meta_box(){
- add_meta_box('painting_order', 'Painting Number', 'post_sort_metabox', 'paintings', 'normal', 'high');
- }
- //create meta box
- function post_sort_metabox(){
- global $post;
- ?>
- <label>Painting Order Number</label>
- <input type="text" value="<?php echo get_post_meta($post->ID, 'painting_order', true); ?>" readonly/>
- <?php
- }
- //construct admin page
- function sort_posts_admin(){
- $taxonomies = get_taxonomies();
- $taxonomy_list = implode(",", $taxonomies);
- //echo $taxonomy_list;
- $category_list = get_terms(array('paintings_type'));
- //echo "<pre>";
- //print_r($category_list);
- //echo "</pre>";
- ?>
- <div class="wrap"></div>
- <p>Sort Post</p>
- <form action="" method="post">
- <select name="category_id">
- <option value="">Select Painting Type</option>
- <?php
- foreach($category_list as $individual):
- ?>
- <option value="<?php echo $individual->slug; ?>"><?php echo $individual->name ?></option>
- <?php endforeach; ?>
- </select>
- <input class="button-primary" type="submit" value="Filter" name="filter" />
- </form>
- </div>
- <form method="post" action="">
- <ul>
- <?php
- if($_POST['filter'] == 'Filter'){
- global $post;
- //$key = $_POST["category_id"];
- $key = $_POST['category_id'];
- $i = 0;
- query_posts( array( 'post_type' => 'paintings', 'showposts' => 100, 'paintings_type' => $key ));
- if ( have_posts() ) : while ( have_posts() ) : the_post();
- ?>
- <li><label><?php echo the_title(); ?></label><input name="<?php $i++; $a = $i-1; echo "updates[$a]"; ?>" value="<?php echo $post->ID .'.'. get_post_meta($post->ID, 'painting_order', true); ?>" /></li>
- <?php
- endwhile;
- endif;
- wp_reset_query();
- ?>
- </ul>
- <input type="submit" name="update" value="Update" />
- </form>
- <?php
- }
- if($_POST['update'] == 'Update'){
- foreach($_POST['updates'] as $update){
- //echo $update;
- $point_slot = strpos($update, ".");
- $point = substr($update, 0, $point_slot);
- $custom_key = "painting_order";
- $value = $update;
- $update_new = str_replace(".", "", stristr($value, "."));
- update_post_meta($point $custom_key, $update_new);
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement