[‘operator’] = ‘or’; outsite searchpage (Similar)
-
Hi,
i use Relevansi outside of the searchpage to get similar content. First i use this snippet:
$query = new WP_Query(); $similar = get_transient('relevanssi_similar_' . $post->ID); if (empty($similar)) { $query->query_vars['s'] = $post->post_title; $query->query_vars['posts_per_page'] = 6; $query->query_vars['operator'] = 'or'; relevanssi_do_query($query); //$similar = "<ul>"; $similar = ""; foreach ($query->posts as $r_post) { if ($r_post->ID == $post->ID) continue; $link = get_permalink($r_post->ID); $title = get_the_title($r_post->ID); $similar .= '<li class="list-group-item"><a href="'.$link.'" title="'.$title.'" >'.$title.'</a></li>'; } //$similar .= "</ul>"; set_transient('relevanssi_similar_' . $post->ID, $similar, 60 * 60 * 24 * 4); } echo $similar;
But partly it comes before the some entries from the internal search not appear in the similar articles.
Therefore, I hollow the entry using the following code:$query = new WP_Query(); $query->query_vars['s'] = $post->post_title; $query->query_vars['posts_per_page'] = 6; $query->query_vars['paged'] = 1; $query->query_vars['operator'] = 'or'; relevanssi_do_query($query); $similar = ""; foreach ($query->posts as $r_post) { if ($r_post->ID == $post->ID) continue; $link = get_permalink($r_post->ID); $title = get_the_title($r_post->ID); $similar .= '<li class="list-group-item"><a href='.$link.' title="'.$title.'" >'.$title.'</a></li>'; } //$similar .= "</ul>"; echo $similar;
Unfortunately the code
$query->query_vars['operator'] = 'or';
does not work here.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘[‘operator’] = ‘or’; outsite searchpage (Similar)’ is closed to new replies.