Advertisement
marikamitsos

wordpress.org/plugins/search-regex/

Dec 14th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. $posts   = $wpdb->get_results ( "SELECT ID, post_content, post_title FROM {$wpdb->posts} WHERE post_status != 'inherit' AND post_type IN ('post','page') ORDER BY ID $orderby" );
  2.  
  3. if ( $limit > 0 )
  4.     $sql .= $wpdb->prepare( " LIMIT %d,%d", $offset, $limit );
  5.  
  6. if (count ($posts) > 0)
  7. {
  8.     foreach ($posts AS $post)
  9.     {
  10.         if (($matches = $this->matches ($pattern, $post->post_content, $post->ID)))
  11.         {
  12.             foreach ($matches AS $match)
  13.                 $match->title = $post->post_title;
  14.  
  15.             $results = array_merge ($results, $matches);
  16.         }
  17.     }
  18. }
  19.  
  20. /*
  21. from http://wordpress.org/support/topic/limit-to-doesnt-work http://daisukeblog.com/?p=2149 change to /path/to/wordpress/wp-conent/plugins/search-regex/searches/post_content.php
  22.  */
  23. $posts   = $wpdb->get_results ( $wpdb->prepare("SELECT ID, post_content, post_title FROM {$wpdb->posts} WHERE post_status != 'inherit' AND post_type IN ('post','page') ORDER BY ID $orderby") );
  24.  
  25. if (count ($posts) > 0)
  26. {
  27.     $hit = 0;
  28.  
  29.     foreach ($posts AS $post)
  30.     {
  31.         if (($matches = $this->matches ($pattern, $post->post_content, $post->ID)))
  32.         {
  33.         ++$hit;
  34.             foreach ($matches AS $match)
  35.                 $match->title = $post->post_title;
  36.  
  37.                 $results = array_merge ($results, $matches);
  38.         }
  39.         if($limit>0&&$hit>=$limit)
  40.         {
  41.             break;
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement