Limited Time Sale - 10% Discount! Use Code:U5ZBQTEY

Alter Query


This document explains how to use the alter query filter hook available in the Divi FilterGrid plugin.

Divi FilterGrid offers several query types that make it easy to display posts and custom post types. Included in the list of available types is a custom query that allows you to code your own complex query. But there may be instances where you simply want to alter the query slightly.

A good example of this might be the related posts query type. Selecting this query type will display posts that are related to the current post or custom post type. But this option is limited to displaying the same post type as the current post type. With the alter query hook, we can modify the query to display other custom post types. In the example below, we are modifying the query to display related recipes:

For this query to work, the recipes custom post type will need to share the same taxonomy as the one selected in the module’s settings. Any recipes that share the same term from the selected taxonomy of the current post will be displayed in the grid. We are also limiting this change to only apply to modules that have the “related-recipes” module class assigned in the Advanced tab -> CSS ID & Classes section. Otherwise it would apply to every instance of the Divi FilterGrid module.

All of the parameters available in the WP_Query class can be added to this filter hook to alter the query however you like. Keep in mind the query parameters added using this filter hook work as an “in addition to” the current query. This is different than the custom query filter hook which completely overrides the query.

Pin It on Pinterest

Share This