Advertisement
alexgieg

Relevanssi category parents indexing

May 24th, 2012
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. // index categories
  2. if ("on" == get_option("relevanssi_include_cats")) {
  3.     $post_categories = get_the_category($post->ID);
  4.     if (is_array($post_categories)) {
  5.         foreach ($post_categories as $p_cat) {
  6.             $cat_name = apply_filters("single_cat_title", $p_cat->cat_name);
  7.             $cat_tokens = relevanssi_tokenize($cat_name);
  8.             foreach ($cat_tokens as $pcat => $count) {
  9.                 if (strlen($pcat) < $min_word_length) continue;
  10.                 $n++;
  11.                 $wpdb->query("INSERT INTO $relevanssi_table (doc, term, tf, title)
  12.                 VALUES ($post->ID, '$pcat', $count, 4)");
  13.             }
  14.             if ("on" == get_option("relevanssi_include_cats_parents")) {
  15.                 $cat_parent = $p_cat;
  16.                 while ($cat_parent->parent && ($cat_parent->parent != $cat_parent->term_id)) {
  17.                     $cat_parent = get_category($cat_parent->parent);
  18.                     $cat_parent_name = apply_filters("single_cat_title", $cat_parent->cat_name);
  19.                     $cat_parent_tokens = relevanssi_tokenize($cat_parent_name);
  20.                     foreach ($cat_parent_tokens as $pcat => $count) {
  21.                         if (strlen($pcat) < $min_word_length) continue;
  22.                         $n++;
  23.                         $wpdb->query("INSERT INTO $relevanssi_table (doc, term, tf, title)
  24.                         VALUES ($post->ID, '$pcat', $count, 4)");
  25.                     }
  26.                 }
  27.             }
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement