Dynamic custom query in Visual Composer Post Grids?

Post Grids is a powerful shortcode allowing listing posts of any type nicely. One of the wonderful options is to use a custom query, which gives much more freedom. Dynamic Shortcode Values further enhances this shortcode allowing you to dynamically composer your custom query by specific context.

Dynamically compose custom query based on URL params

Lets say you want to list products by specific criteria. One of the params will be product price and you want to be able to set this param via URL.

To do so you set your custom query to post_type=product&meta_key=_price&meta_value=__SEARCH_BY_PRICE__&posts_per_page=20

__SEARCH_BY_PRICE__ - is your custom text placeholder that could be automatically replaced. To do so, you need to go to Dynamic Values tab, choose "Custom text placeholder" and input __SEARCH_BY_PRICE__ in the textbox. On the right side you pick the replacement value, which in this case should be HTTP type and price GET param.

Such setup allows to type ?price=xxx in URL and the products list will be adjusted automatically.

Here is the sample below which lists the products by price. Give it a try and see how price filters work:

Recent Posts