This is really confusing me. Hopefully you can help me. What i want to do, is search for a number and display anything that is either minus 1 or plus one of the search result. The numbers that it will be searching for will have decimals, for example 12.5. So if i searched for 12.5 it should display 11.5, 11.6 all the way up to 13.5. I have the search part of it done its just displaying the posts is my issue. The code i have so far is:
<?php
$search_query = get_search_query();
$searchplusone = ++$search_query ;
$search_query1 = get_search_query();
$searchnegone = --$search_query1 ;
$args = (array(
'post_type' => 'product',
'numberposts' => -1,
'meta_query' => array(
array(
'value' => array( $searchnegone, $searchplusone),
'key' => 'kilowatt',
'type' => 'decimal',
'compare' => 'BETWEEN',
)),
) );
$the_query = new WP_Query( $args );
?>
<?php echo $search_query; echo $searchnegone; echo $searchplusone;
print_r ($args);
?>
<?php if( $the_query->have_posts() ): ?>
<ul>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query();
?>
It seems to work when you search for 12.5, but when you search for 11.5 or even 11.9 it doesnt display the posts, but if you search for 14 it will display the posts which has the value 12.5 even though its not meant to because it should be comparing and displaying the posts between 13 and 15. It should, however display 11.9 because it is in range of 12.5.
EDIT: After further investigation, i discovered that if the number in the post is set to say 20 and you search for 19.1, 19.2 etc it will display the correct post. It just seems to be when the post has a number set that is a decimal it causes the problem.