Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 19th, 2013  |  syntax: None  |  size: 2.05 KB  |  views: 35  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. $search_terms = "example search" // input post
  2. // remove single quotes from search terms
  3. $search_terms = str_replace("'","",$search_terms);
  4.  
  5. $sql = "SELECT
  6.     post.ID,
  7.     post.post_author,
  8.     post.post_date,
  9.     post.post_title,
  10.     LEFT(post.post_content, 240) As post_content,
  11.     post.post_name,
  12.     post.post_type,
  13.     post.comment_count,
  14.     post.comment_status,
  15.     MATCH (post_search.post_content,post_search.post_title) AGAINST (%s IN BOOLEAN MODE) AS score
  16. FROM wp_posts post
  17. LEFT JOIN wp_term_relationships term_rel
  18.     ON post.ID = term_rel.object_id
  19. LEFT JOIN wp_term_taxonomy term_tax
  20.     ON term_rel.term_taxonomy_id = term_tax.term_taxonomy_id
  21. LEFT JOIN wp_terms terms
  22.     ON term_tax.term_id = terms.term_id
  23. LEFT JOIN wp_posts_fulltext_search post_search
  24.     ON post.ID=post_search.post_id
  25. WHERE MATCH(post_search.post_content,post_search.post_title) AGAINST (%s IN BOOLEAN MODE) &&
  26.     post.post_status = 'publish' &&
  27.     post.post_type = 'post' &&
  28.     (term_tax.description != '' &&
  29.     term_tax.description NOT LIKE '%sample%')
  30. GROUP BY post.ID
  31. ORDER BY score DESC
  32. LIMIT 0,20";
  33.  
  34. $results = $wpdb->get_results( $wpdb->prepare( $sql, $search_terms ) );
  35.        
  36. // remove single quotes from search terms
  37. $search_terms = str_replace("'","",$search_terms);
  38.        
  39. $search_terms = mysql_real_escape_string($search_terms);
  40.        
  41. <?php
  42.   $sql = $wpdb->prepare('query' [, value_parameter, value_parameter ... ] );
  43. ?>
  44.        
  45. $metakey = "Harriet's Adages";
  46. $metavalue = "WordPress' database interface is like Sunday Morning: Easy.";
  47.  
  48. $wpdb->query( $wpdb->prepare( "
  49.     INSERT INTO $wpdb->postmeta
  50.     ( post_id, meta_key, meta_value )
  51.     VALUES ( %d, %s, %s )",
  52.         10, $metakey, $metavalue ) );
  53.        
  54. $metakey = "Harriet's Adages";
  55. $metavalue = "WordPress' database interface is like Sunday Morning: Easy.";
  56.  
  57. $wpdb->query( $wpdb->prepare( "
  58.     INSERT INTO $wpdb->postmeta
  59.     ( post_id, meta_key, meta_value )
  60.     VALUES ( %d, %s, %s )",
  61.         array(10, $metakey, $metavalue) ) );
  62.        
  63. term_tax.description NOT LIKE '%sample%')
  64.        
  65. term_tax.description NOT LIKE '%%sample%%')
clone this paste RAW Paste Data