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!

2 comments:

  1. Thanks for the script, many will be useful. At one time I was looking for a similar script for solving my problem on my site. The problem was the compatibility of the plugin to manage the fonts on the site with the wordpress template https://www.templatemonster.com/ru/woocommerce-themes-type/. I searched a lot on the Internet, I spent quite a lot of time before I solved my problem

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete