Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.50 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Sort Posts
  4. Description: Allows for the reordering of posts
  5. */
  6. //actions
  7. //add buttton to dashboard
  8. add_action('admin_menu','add_sort_post_button');
  9. //add meta box
  10. add_action('admin_init','add_painting_meta_box');
  11. //add button to plugins menu
  12. function add_sort_post_button(){
  13.     add_submenu_page('plugins.php', 'Sort Posts', 'Sort Posts', 'manage_options', 'sort-posts','sort_posts_admin');
  14. }
  15. //add_meta box
  16. function add_painting_meta_box(){
  17.     add_meta_box('painting_order', 'Painting Number', 'post_sort_metabox', 'paintings', 'normal', 'high');
  18. }
  19. //create meta box
  20. function post_sort_metabox(){
  21.     global $post;
  22. ?>
  23. <label>Painting Order Number</label>
  24. <input type="text" value="<?php echo get_post_meta($post->ID, 'painting_order', true); ?>" readonly/>
  25. <?php
  26. }
  27. //construct admin page
  28. function sort_posts_admin(){
  29.     $taxonomies = get_taxonomies();
  30.     $taxonomy_list = implode(",", $taxonomies);
  31.     //echo $taxonomy_list;
  32.     $category_list = get_terms(array('paintings_type'));
  33.     //echo "<pre>";
  34.     //print_r($category_list);
  35.     //echo "</pre>";
  36. ?>
  37. <div class="wrap"></div>
  38. <p>Sort Post</p>
  39. <form action="" method="post">
  40. <select name="category_id">
  41. <option value="">Select Painting Type</option>
  42. <?php
  43. foreach($category_list as $individual):
  44. ?>
  45. <option value="<?php echo $individual->slug; ?>"><?php echo $individual->name ?></option>
  46. <?php endforeach; ?>
  47. </select>
  48. <input class="button-primary" type="submit" value="Filter" name="filter" />
  49. </form>
  50. </div>
  51. <form method="post" action="">
  52. <ul>
  53. <?php  
  54. if($_POST['filter'] == 'Filter'){
  55.     global $post;
  56.     //$key = $_POST["category_id"];
  57.     $key = $_POST['category_id'];
  58.         $i = 0;
  59. query_posts( array( 'post_type' => 'paintings', 'showposts' => 100, 'paintings_type' => $key ));
  60.  
  61. if ( have_posts() ) : while ( have_posts() ) : the_post();
  62.  
  63. ?>
  64.     <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>
  65. <?php  
  66.     endwhile;
  67.     endif;
  68.     wp_reset_query();
  69. ?>
  70. </ul>
  71. <input type="submit" name="update" value="Update" />
  72. </form>
  73. <?php
  74. }
  75. if($_POST['update'] == 'Update'){
  76.  
  77. foreach($_POST['updates'] as $update){
  78.  
  79.     //echo $update;
  80.     $point_slot = strpos($update, ".");
  81.     $point =  substr($update, 0, $point_slot);
  82.     $custom_key = "painting_order";
  83.     $value = $update;
  84.     $update_new = str_replace(".", "", stristr($value, "."));
  85.     update_post_meta($point $custom_key, $update_new);
  86.     }
  87.  
  88. }
  89.  
  90. }
  91.  
  92. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement