Advertisement
terorama

PHP / WP Snippets

Jun 9th, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.20 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. define ('WP_USE_THEMES',false);
  5. require('../wp-load.php');
  6. ini_set('display_errors',1);
  7. error_reporting(E_ALL);
  8. header('Content-type:text/html; charset=utf-8');
  9.  
  10. global $wpdb;
  11.  
  12. $wpdb->show_errors();
  13.  
  14.  
  15. $rez = $wpdb->get_results(
  16. 'select count(*), a.post_type, d.taxonomy, e.name, max(a.post_date)
  17.           from wp_posts a left outer join wp_term_relationships b on
  18.              a.id=b.object_id left outer join wp_term_taxonomy d on
  19.              b.term_taxonomy_id=d.term_taxonomy_id
  20.          left outer join wp_terms e on d.term_id=e.term_id
  21.  group by a.post_type, d.taxonomy, e.name order by a.post_type, d.taxonomy, e.name
  22. ', ARRAY_N);
  23.  
  24.  
  25.  
  26.  
  27. foreach ($rez as $row) {
  28.    echo date('d.m.Y',strtotime($row[4])).' '.$row[1].' '.$row[2].' '.$row[3].' - '.$row[0].'<br/>';
  29. }
  30.  
  31. ?>
  32.  
  33.  
  34.  
  35. <?php
  36. //--------------------------------------------------------------------
  37.  
  38. define ('WP_USE_THEMES',false);
  39. require('../wp-load.php');
  40. ini_set('display_errors',1);
  41. error_reporting(E_ALL);
  42. header('Content-type:text/html; charset=utf-8');
  43.  
  44. session_start();
  45.  
  46. $step = isset($_SESSION['step']) && isset($_GET['step']) ? $_SESSION['step'] : 0;
  47.  
  48. if (!isset($_GET['step']))
  49.    $_SESSION['zdate'] = strtotime('2013-6-5');
  50.  
  51. $q = new WP_Query(array('post_type'=>'digest', 'offset'=>$step*10, 'posts_per_page'=>10,
  52.  'orderby'=>'date', 'order'=>'DESC'));
  53.  
  54. while ($q->have_posts()) {
  55.    $q->the_post();
  56.    echo get_the_id().' '.get_the_title().' '.get_the_date('d.m.Y H:i',get_the_id()).'<br/>';
  57.  
  58.    if (strtotime(get_the_date('Y-m-d',get_the_id()))==$_SESSION['zdate']) {
  59.       echo 'date get<br/>';
  60.       $_SESSION['zdate'] = $_SESSION['zdate']-20*24*3600;
  61.  
  62.       wp_set_object_terms(get_the_id(), 'primary_dir', 'direction');
  63.    }
  64.    else {
  65.       delete_all(get_the_id());
  66.    }
  67.  
  68.    //$inf = get_term_by('slug','primary_dir','direction');
  69.    //$inf = $inf->term_id;
  70.  
  71.  
  72. }
  73.  
  74.  
  75. //---------------------------
  76. function delete_all($pid) {
  77.  
  78.  $imgs = array();
  79.  $pids = array();
  80.  
  81.  if (has_post_thumbnail($pid)) {
  82.       $tid = get_post_thumbnail_id($pid);
  83.       $pids[] = $tid;
  84.    }
  85.  
  86.    
  87.    foreach (array('thumbnail','medium','large','full') as $size) {
  88.       $imgs[] = reset(wp_get_attachment_image_src($tid, $size));
  89.    }
  90.    
  91.    $imgs[] = wp_get_attachment_thumb_url($tid);
  92.  
  93.  
  94.    $att = & get_children(array('post_type'=>'attachment','post_parent'=>$pid));
  95.    foreach ($att as $attt) {
  96.      
  97.       $pids[] = $attt->ID;
  98.       $imgs[] = get_attached_file($attt->ID);
  99.  
  100.       foreach (array('thumbnail','medium','large','full') as $size) {
  101.          $imgs[] = reset(wp_get_attachment_image_src($attt->ID,$size));
  102.        }
  103.    
  104.    }
  105.  
  106.   $pids = array_unique($pids);
  107.   $imgs = array_unique($imgs);
  108.  
  109.   echo '<pre>'.print_r($imgs,true).print_r($pids,true).'</pre>';
  110.  
  111.   foreach ($pids as $pidz) {
  112.      wp_delete_post($pidz, true);
  113.  }
  114.  wp_delete_post($pid, true);
  115. }
  116.  
  117. echo '<br/><br/>current step: '.$step;
  118. echo '<br/>date: '.date('d.m.Y', $_SESSION['zdate']);
  119. $step++;
  120. $_SESSION['step'] = $step;
  121.  
  122. ?>
  123.  
  124. <div id="countz"></div>
  125. <script type="text/javascript">
  126.    window.onload = function () {
  127.  
  128.       var tm= 5;
  129.       var zz = setInterval( function() {
  130.          var uu = document.getElementById('countz');
  131.          uu.innerHTML = 'reload after '+tm+ ' s';
  132.          tm--;
  133.          if (tm==0) {
  134.             clearInterval(zz);
  135.             location.replace('<?php echo $_SERVER['PHP_SELF'].'?step';?>');
  136.          }
  137.        
  138.       } , 1000)
  139.    }
  140. </script>
  141.  
  142.  
  143. <?php
  144. //----------------------------------------------
  145.  
  146. define ('WP_USE_THEMES',false);
  147. require('../wp-load.php');
  148. ini_set('display_errors',1);
  149. error_reporting(E_ALL);
  150. header('Content-type:text/html; charset=utf-8');
  151.  
  152.  
  153. global $wpdb;
  154.  
  155. $rez = $wpdb->get_results('select count(*), post_type from wp_posts group by post_type', ARRAY_N);
  156.  
  157. foreach ($rez as $row) {
  158.    echo $row[1].' '.$row[0].'<br/>';
  159. }
  160.  
  161.  
  162. ?>
  163.  
  164. <?php
  165. //----------------------------------------------
  166. define ('WP_USE_THEMES',false);
  167. require('../wp-load.php');
  168. ini_set('display_errors',1);
  169. error_reporting(E_ALL);
  170. header('Content-type:text/html; charset=utf-8');
  171.  
  172. $args = array('posts_per_page'=>10, 'orderby'=>'modified', 'order'=>'DESC','post_type'=>'digest');
  173.  
  174. $posts = get_posts($args);
  175.  
  176. foreach ($posts as $el) {
  177.  
  178.    if (has_post_thumbnail($el->ID)) {
  179.       $img = get_post_thumbnail_id($el->ID, 'thumbnail');
  180.    }
  181.    $category = get_the_category($el->ID);
  182.    
  183.    echo $el->ID.' '.$el->post_title.' '.$el->post_modified.' '.$category[0]->name.'<br/>';
  184.  
  185.    
  186. }
  187. ?>
  188.  
  189. <?php
  190. //----------------------------------------------
  191. define ('WP_USE_THEMES',false);
  192. require('../wp-load.php');
  193. ini_set('display_errors',1);
  194. error_reporting(E_ALL);
  195. header('Content-type:text/html; charset=utf-8');
  196.  
  197.  
  198. get_cats(0);
  199.  
  200. function get_cats($parent) {
  201.  
  202. $cats = get_categories('hide_empty=0&parent='.$parent);
  203. if (count($cats)==0)
  204.    return;
  205.  
  206. echo '<div style="margin-left:50px;">';
  207. foreach ($cats as $el) {
  208.    
  209.    echo $el->term_id.' '.$el->name.' '.$el->slug.' '.$el->count.'<br/>';
  210.    get_cats($el->term_id);
  211.  
  212. }
  213. echo '</div>';
  214.  
  215. }
  216.  
  217. ?>
  218.  
  219. <?php
  220. //----------------------------------------------
  221. define ('WP_USE_THEMES',false);
  222. require('../wp-load.php');
  223. ini_set('display_errors',1);
  224. error_reporting(E_ALL);
  225. header('Content-type:text/html; charset=utf-8');
  226.  
  227. session_start();
  228.  
  229. $step = (isset($_SESSION['step'])) ? $_SESSION['step'] : 0;
  230.  
  231.  
  232.    
  233.    $args = array('posts_per_page'=>10, 'offset'=>$step*10);
  234.    $posts = get_posts($args);
  235.  
  236.    if (count($posts)==0)
  237.       break;
  238.  
  239.  
  240.    foreach ($posts as $el) {
  241.        echo $el->ID.' '.$el->ping_status.'<br/>';
  242.        if ($el->ping_status=='open') {
  243.           wp_update_post(array('ID'=>$el->ID, 'ping_status'=>'closed'));
  244.           echo '*** '.$el->ID.' '.$el->post_title.' '.$el->ping_status.'<br/>';
  245.        }
  246.    }
  247.    
  248.  
  249.  
  250. echo '</table>';
  251. echo 'current step '.$step.'<br/>';
  252.  
  253. $_SESSION['step']=$step+1;
  254.  
  255. ?>
  256. <div id="counterr"></div>
  257.  
  258. <script type="text/javascript">
  259.    window.onload = function() {
  260.       var cnt=5;
  261.       var zz = setInterval( function() {
  262.           var uu = document.getElementById('counterr');
  263.           uu.innerHTML = 'reload after '+cnt+' s';
  264.           cnt--;
  265.           if (cnt==0) {
  266.              clearInterval(zz);
  267.              location.replace(location.href);
  268.           }
  269.       }, 1000)
  270.    }
  271. </script>
  272.  
  273. <?php
  274. //----------------------------------------------
  275. define ('WP_USE_THEMES',false);
  276. require('../wp-load.php');
  277. ini_set('display_errors',1);
  278. error_reporting(E_ALL);
  279. header('Content-type:text/html; charset=utf-8');
  280.  
  281.  
  282.    echo '<table style="border:solid 1px;"><tr><td>post</td><td>link</td><td>parent</td><td>meta</td>
  283.     <td>date</td><td>start</td>
  284. </tr>';
  285.  
  286. for ($i=0; $i<1000; $i++) {
  287.    
  288.    $args = array('posts_per_page'=>10, 'offset'=>$i*10, 'post_type'=>'attachment');
  289.    $posts = get_posts($args);
  290.  
  291.    if (count($posts)==0)
  292.       break;
  293.  
  294.  
  295.    foreach ($posts as $el) {
  296.      
  297.       echo '<tr>';
  298.       echo '<td style="border: solid 1px;">'.$el->ID.' '.$el->post_title.'</td>';
  299.       $link = wp_get_attachment_image_src($el->ID,'full');
  300.       echo '<td>'.$link[0].'</td>';
  301.       $parent = get_post_ancestors($el->ID,false);
  302.       echo '<td>'.$parent[0].'</td>';
  303.       echo '<td></td></tr>';
  304.    }
  305.    
  306.  
  307. }
  308.  
  309. echo '</table>';
  310.  
  311. ?>
  312.  
  313. <?php
  314. //----------------------------------------------
  315. define ('WP_USE_THEMES',false);
  316. require('../wp-load.php');
  317. ini_set('display_errors',1);
  318. error_reporting(E_ALL);
  319. header('Content-type:text/html; charset=utf-8');
  320.  
  321.  
  322. for ($i=0; $i<1000; $i++) {
  323.    
  324.    $args = array('posts_per_page'=>10, 'offset'=>$i*10);
  325.    $posts = get_posts($args);
  326.  
  327.    if (count($posts)==0)
  328.       break;
  329.  
  330.    echo '<table><tr><td>post</td><td>categories</td><td>tags</td><td>meta</td></tr>';
  331.  
  332.    foreach ($posts as $el) {
  333.       echo '<tr><td>'.$el->ID.' '.$el->post_title.'</td>';
  334.       $cats = get_the_category($el->ID);
  335.  
  336.       foreach ($cats as $key=>$cat) {
  337.          $cats[$key] = $cat->name;
  338.       }
  339.       echo '<td>'.implode(',', $cats).'</td>';
  340.      
  341.      
  342.       $tags = get_the_tags($el->ID);
  343.       $f = create_function('$a','return $a->name;');
  344.      
  345.       if (!is_array($tags))
  346.          $tags = array();
  347.  
  348.       $tags = array_map($f, $tags);
  349.      
  350.  
  351.       echo  '<td>'.implode(',', $tags).'</td>';
  352.       echo  '<td></td>';
  353.       echo '</tr>';
  354.    }
  355.    echo '</table>';
  356.  
  357. }
  358.  
  359.  
  360. ?>
  361.  
  362. <?php
  363. //----------------------------------------------
  364. define ('WP_USE_THEMES',false);
  365. require('../wp-load.php');
  366. ini_set('display_errors',1);
  367. error_reporting(E_ALL);
  368.  
  369. $arr = array();
  370.  
  371. for ($i=0; $i<100; $i++) {
  372.    
  373.    $args = array('posts_per_page'=>10, 'offset'=>$i*10);
  374.    echo $i.' - ';
  375.    $posts = get_posts($args);
  376.    if (count($posts)==0)
  377.       break;
  378.  
  379.    foreach ($posts as $el) {
  380.       if ($el->comment_count>0 ) {
  381.          $arr[] = $el;
  382.       }
  383.    }
  384.    
  385. }
  386.  
  387. echo '<br/>';
  388. $urls = array();
  389. ob_start();
  390. while (list($key,$val) = each($arr)) {
  391.    echo $val->ID.' '.$val->post_title.' '.$val->comment_count.'<br/><br/>';
  392.    
  393.    $args = array('post_id'=>$val->ID);
  394.    $comm = get_comments($args);
  395.  
  396.    echo '<table><tr><th>id</th><th>author</th><th>email</th><th>comm</th><th>type</th>'.
  397.       '<th>date</th><th>userid</th></tr>';
  398.  
  399.    foreach ($comm as $el) {
  400.       echo '<tr><td>'.$el->comment_ID.'</td><td>'.$el->comment_author.
  401.       '</td><td>'.$el->comment_author_url.'</td><td>'.
  402.        $el->comment_content.'</td><td>'.$el->comment_type.'</td><td>'.
  403.       $el->comment_date.'</td><td>'.$el->user_id.'</td></tr>';
  404.  
  405.       $urls[] = $el->comment_author_url;
  406.      
  407.    }
  408.    echo '</table>';
  409.  
  410. }
  411. $tabb = ob_get_clean();
  412.  
  413. $urls = (array_count_values($urls));
  414. arsort($urls);
  415.  
  416. ob_start();
  417. echo '<table><tr><td>url</td><td>count</td></tr>';
  418. foreach ($urls as $key=>$value) {
  419.    echo '<tr><td>'.$key.'</td><td>'.$value.'</td></tr>';
  420. }
  421. echo '</table>';
  422. $tabb4 = ob_get_clean();
  423.  
  424. $urls = array_keys($urls);
  425.  
  426. $urls = array_map('zzz', $urls);
  427.  
  428. function zzz($a) {
  429.    return str_replace(strstr(substr(strstr($a,'//'),2),'/'),'',$a);
  430. }
  431.  
  432.  
  433. //$urls = array_values(array_unique($urls));
  434. $urls = array_count_values ($urls);
  435. arsort($urls);
  436.  
  437.  
  438. while (list($key,$val)  = each($urls)) {
  439.    echo $key.' '.$val.'<br/>';
  440. }
  441.  
  442. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement