That scrolling is not a Relevanssi feature, so I can’t help you with that.
If the highlighting is powered by Relevanssi, that’ll require some changes in your custom template. Relevanssi by default only highlights terms in post content (because it’s done using the_content filter hook).
Relevanssi has a function called relevanssi_highlight_terms(), which you can use to highlight the custom field content in your template.
I tried adding this to the page’s template but there’s no difference in what’s outputted.
if (isset($wp_query->query_vars['s'])) {
echo relevanssi_highlight_terms(get_field('additional_information'),$wp_query->query_vars['s']);
}
Here’s a sample URL http://waterwayplastics.com/products/pool-products/chlorinators/chlorinators-2/#s=”400-5200″
Any ideas what I’m doing wrong?
Can you show me the complete template?
Here’s the template code:
<?php
/*
Template Name: Product Detail
*/
?>
<?php get_header(); ?>
<div id="content_wrapper" class="clearfix secondary_sidebar">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="category_banner" class="grid_12 clearfix">
<div id="category_info">
<div>
<?php $title = get_field('product_title') ? get_field('product_title') : get_the_title(); echo('<div id="page_title">' . $title . '</div>'); ?>
<?php get_field('description') ? the_field('description') : ''; ?>
<?php if($post->post_parent) {
$parent_link = get_permalink($post->post_parent);
$parent_title = get_the_title($post->post_parent);
if ($parent_title <> 'Products') {
?>
<p><a href="<?php echo $parent_link; ?>">Return to <?php echo $parent_title; ?></a></p>
<?php } } ?>
</div>
</div>
<?php $image = wp_get_attachment_image_src(get_field('product_image'), 'category-thumb'); ?>
<img src="<?php echo $image[0]; ?>" alt="" style="display: block; margin: 0 auto;" />
</div>
<!-- Begin Additional Info Toggle Box -->
<?php if (get_field('additional_information')) { ?>
<div class="grid_12">
<div id="product_specs_box_wrapper">
<a href="#" id="togglebox">
<h2><?php $boxheading = get_field('product_toggle_box_heading') ? get_field('product_toggle_box_heading') : "Specifications"; echo $boxheading; ?></h2>
</a>
<div id="product_specs_box" class="clearfix">
<?php
if (isset($wp_query->query_vars['s'])) {
echo relevanssi_highlight_terms(get_field('additional_information'),$wp_query->query_vars['s']);
} else {
the_field('additional_information');
}
?>
</div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#togglebox').click(function() {
toggleLink = $(this).parent().find('#togglebox');
if (toggleLink.hasClass('expanded')) {
toggleLink.removeClass('expanded');
} else {
toggleLink.addClass('expanded');
}
$('#product_specs_box').fadeToggle();
return false;
});
$('.product_chart tr:nth-child(even)').addClass('alt');
console.log(document.referrer);
});
</script>
<?php } ?>
<!-- End Additional Info Toggle Box -->
<?php endwhile; else: ?>
<p>
<?php _e('Sorry, no posts matched your criteria.'); ?>
</p>
<?php endif; ?>
</div>
<?php get_footer(); ?>
Instead of $wp_query->query_vars['s'])
, use get_search_query()
or add global $wp_query;
before it.
I tried it both ways:
global $wp_query;
echo relevanssi_highlight_terms(get_field('additional_information'),$wp_query->query_vars['s']);
and
global $wp_query;
echo relevanssi_highlight_terms(get_field('additional_information'),get_search_query());
But still no change. I tried hard coding a term in the code and the highlighting worked, so it looks like it’s just not able to access the variable in the querystring.
Ah, indeed. It is not a search results template, so the search query is going to be empty. You need to get the search query from $_SERVER[‘HTTP_REFERER’].
Try this:
echo relevanssi_highlight_in_docs(get_field('additional_information'));