Advertisement
dipaksaraf

WordPress Code

Apr 17th, 2011
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.17 KB | None | 0 0
  1. <div style="width: 500px;">
  2. <form method="post" action="/extract-ads/" >
  3. <table>
  4. <tr>
  5. <td>Select Category</td>
  6. <td><select name="cat">
  7.     <option value="">All</option>
  8.     <option value="4">Option 1</option>
  9.     <option value="5">Option 2</option>
  10.     <option value="6">Option 3</option>
  11.     <option value="7">Option 4</option>
  12.     <option value="3">Option 6</option>
  13.         <option value="8">Featured</option>
  14. </select></td>
  15. </tr>
  16. <tr>
  17. <td>Start Date:</td>
  18. <td><input type="text" name="startdate" value="YYYY-MM-DD"/></td>
  19. </tr>
  20. <tr>
  21. <td>End Date:</td>
  22. <td><input type="text" name="enddate" value="YYYY-MM-DD"/></td>
  23. </tr>
  24. <tr>
  25. <td colspan="2"><input type="submit" value="Get extract" /></td>
  26. </tr>
  27. </table>
  28. </form>
  29. </div>
  30.  
  31. <?php
  32. if (isset($_REQUEST['cat'])){
  33.  
  34. function limit1k( $limits ) {
  35.     return 'LIMIT 1000';
  36. }
  37. add_filter( 'post_limits', 'limit1k' );
  38.  
  39.     function filter_where( $where = '' ) {
  40.         $where .= " AND post_date >= '{$_REQUEST['startdate']}' AND post_date < '{$_REQUEST['enddate']}'";
  41.         return $where;
  42.     }
  43.     add_filter( 'posts_where', 'filter_where' );
  44.  
  45. $recent = get_posts("cat={$_REQUEST['cat']}&suppress_filters=0&orderby=category");
  46.  
  47. foreach( $recent as $post ){
  48.      $ID_Code = get_post_meta($post->ID,'ID_Code',true);
  49.      $Customer_type = get_post_meta($post->ID,'Contact_Customer_Type',true);
  50.      $this_cat = get_the_category($post->ID);
  51.      $permalink = get_permalink($post->ID);
  52.      $output[] = array($ID_Code, $this_cat[0]->cat_name, trim(strip_tags($post->post_content)), $Customer_type, $permalink, trim(strip_tags($post->post_content)).' Ad Code: '.$ID_Code."\n\n");
  53. }
  54.  
  55. function custom_sort($a, $b)
  56.   {
  57.     $retval = strnatcmp($a[1], $b[1]);
  58.     if(!$retval) return strnatcmp($a[3], $b[3]);
  59.     return $retval;
  60.   }
  61. usort($output, 'custom_sort');
  62.  
  63. array_unshift($output, array("'ID_Code", 'Category', 'Content', 'Customer Type', 'URL', 'Formatted Data'));
  64.  
  65. //print_r($output);
  66.  
  67.  
  68. $fp = fopen('/home/public_html/wp-content/themes/fta/downloads/report.csv', 'w+');
  69.  
  70. foreach ($output as $fields) {
  71.     fputcsv($fp, $fields);
  72. }
  73.  
  74. fclose($fp);
  75. echo '<p>The report file has been updated.  <a href="/wp-content/themes/fta/downloads/report.csv">Dowload here</a>.</p>';
  76. }
  77. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement