Sunday, April 2, 2017

Ajax Load More Shortcode Builder - "Between" Operator

This is just a quick tip for those looking for the same information I just was - if you are looking to use the "Between" operator in conjunction with the "Custom Fields (Meta_Query" filtering part of the Ajax Load More Wordpress plugin, still use the "meta_value" parameter. However, you don't pass in an array (it is expecting a string). Pass it your two values, separated by a comma.

For example, if you have a custom field with the key "price", and you want the load more button to pull in more posts that have the "price" set to between $10 and $20, your shortcode should look something like this:

[ajax_load_more post_type="post" meta_key="product_price" meta_value="10,20" meta_compare="BETWEEN" meta_type="NUMERIC"]
If you want to fill in the range with PHP, simply use the dot concatenation to join the shortcode string with a variable. For example:

<?php echo do_shortcode('[ajax_load_more post_type="post" meta_key="product_price" meta_value="'.$price_low.','.$price_high.'" meta_compare="BETWEEN" meta_type="NUMERIC"]'); ?>
Happy coding!