Code Samples /

posts_where

In WordPress, posts_where is a hook used to modify the WHERE clause of an SQL query underlying a WP_Query. With Ajax Load More, there are a couple of ways you can use a posts_where filter to modify the custom plugin query.

Custom Args

Use the custom_args parameter to pass custom query options directly to the Ajax Load More WP_Query.

In the code sample below, a starts_with key/value pair has been set via Ajax Load More shortcode using the custom_args parameter and then accessed in the posts_where filter to modify the SQL query on the server side.

Query ID

All Ajax Load More queries have a custom alm_id parameter attached to the WP_Query, this parameter allows developers to target a specific instance of Ajax Load More for modification while using posts_where.

The following code sample will run the posts_where filter only when this specific instance of Ajax Load More is active.


« Back to Code Samples