Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div style="width: 500px;">
- <form method="post" action="/extract-ads/" >
- <table>
- <tr>
- <td>Select Category</td>
- <td><select name="cat">
- <option value="">All</option>
- <option value="4">Option 1</option>
- <option value="5">Option 2</option>
- <option value="6">Option 3</option>
- <option value="7">Option 4</option>
- <option value="3">Option 6</option>
- <option value="8">Featured</option>
- </select></td>
- </tr>
- <tr>
- <td>Start Date:</td>
- <td><input type="text" name="startdate" value="YYYY-MM-DD"/></td>
- </tr>
- <tr>
- <td>End Date:</td>
- <td><input type="text" name="enddate" value="YYYY-MM-DD"/></td>
- </tr>
- <tr>
- <td colspan="2"><input type="submit" value="Get extract" /></td>
- </tr>
- </table>
- </form>
- </div>
- <?php
- if (isset($_REQUEST['cat'])){
- function limit1k( $limits ) {
- return 'LIMIT 1000';
- }
- add_filter( 'post_limits', 'limit1k' );
- function filter_where( $where = '' ) {
- $where .= " AND post_date >= '{$_REQUEST['startdate']}' AND post_date < '{$_REQUEST['enddate']}'";
- return $where;
- }
- add_filter( 'posts_where', 'filter_where' );
- $recent = get_posts("cat={$_REQUEST['cat']}&suppress_filters=0&orderby=category");
- foreach( $recent as $post ){
- $ID_Code = get_post_meta($post->ID,'ID_Code',true);
- $Customer_type = get_post_meta($post->ID,'Contact_Customer_Type',true);
- $this_cat = get_the_category($post->ID);
- $permalink = get_permalink($post->ID);
- $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");
- }
- function custom_sort($a, $b)
- {
- $retval = strnatcmp($a[1], $b[1]);
- if(!$retval) return strnatcmp($a[3], $b[3]);
- return $retval;
- }
- usort($output, 'custom_sort');
- array_unshift($output, array("'ID_Code", 'Category', 'Content', 'Customer Type', 'URL', 'Formatted Data'));
- //print_r($output);
- $fp = fopen('/home/public_html/wp-content/themes/fta/downloads/report.csv', 'w+');
- foreach ($output as $fields) {
- fputcsv($fp, $fields);
- }
- fclose($fp);
- echo '<p>The report file has been updated. <a href="/wp-content/themes/fta/downloads/report.csv">Dowload here</a>.</p>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement