WP Residence Help WP Residence Help

  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API
Home / Technical: Actions and filters / How to Change Default Query Settings Per Page Type

How to Change Default Query Settings Per Page Type

115 views 0

Filter: wpestate_query_2026_context_defaults

This filter allows you to change the base default values that every property query
starts with. These defaults control settings like how many properties are shown per page, what sort
order is used, and whether the query returns full post objects or just IDs.

The WP Residence query engine uses four different contexts to determine what kind of
page is requesting properties: directory (listing pages), map (map pin queries), dashboard (front-end
agent panel), and featured (widgets and shortcodes). Each context has its own set of defaults. This
filter lets you change those defaults from your child theme.


When Does This Filter Fire?

This filter fires at the very beginning of the query pipeline, inside the function
wpestate_query_2026_property_context_defaults(). It runs before the
caller’s parameters are merged in. This means the values you set here act as fallbacks —
if the caller (a page template, a shortcode, or a search form) provides an explicit value for the
same setting, the caller’s value will take priority over your default.

Source file: libs/query/query2026/wpestate_query_2026_property.php


Filter Signature

$defaults = apply_filters( 'wpestate_query_2026_context_defaults', $defaults, $context );

Parameters

Parameter Type Description
$defaults array The defaults array that you can modify. This is the value you must return from your
callback function.
$context string The query context. One of: ‘directory’, ‘map’,
‘dashboard’, or ‘featured’. Use this to apply your changes
only to specific page types.

Default Values in the Array

When this filter fires, the $defaults array contains these keys with their built-in
values. Context-specific overrides (for example, map queries set fields to
'ids') are already applied before the filter fires.

Key Default Value What It Controls
post_status ‘publish’ Which post status to query. Almost always ‘publish’ on the front-end.
paged 1 The current pagination page number.
posts_per_page 0 How many properties to show per page. 0 means “use the WordPress site setting” (Settings → Reading).
order 0 Sort order code. 0 = featured properties first, then by date. Codes 1–8 map to specific sort options (newest, price, bedrooms, size, etc.).
no_found_rows false When true, WordPress skips counting total matching posts. Faster, but pagination will not work. Map and featured contexts set this to true by default.
fields ” (empty string) What data to return. Empty string = full WP_Post objects. ‘ids’ = only post IDs (faster). Map context uses ‘ids’ by default.
tax_relation ‘AND’ How multiple taxonomy filters combine. ‘AND’ = property must match ALL taxonomy filters. ‘OR’ = property must match at least one.
meta_relation ‘AND’ How multiple meta (custom field) filters combine. Works the same way as tax_relation.
geo_lat ” Geolocation center latitude. Empty = no geolocation filtering.
geo_long ” Geolocation center longitude.
geo_rad 0 Geolocation search radius (in the unit configured in theme options: miles or kilometers).

Child Theme Examples

Example 1: Show 24 Properties Per Page on Directory Listing Pages

By default, directory pages use the WordPress “posts per page” setting (Settings → Reading).
If you want directory pages to always show 24 properties per page regardless of that WordPress setting,
you can change the default like this:

<?php
/**
 * Change the default number of properties shown on directory listing pages to 24.
 *
 * This only changes the default. If a specific page template or shortcode explicitly
 * sets a different posts_per_page value, that value will override this default.
 *
 * Add this code to your child theme's functions.php file.
 */
add_filter( 'wpestate_query_2026_context_defaults', 'my_child_change_directory_per_page', 10, 2 );
function my_child_change_directory_per_page( $defaults, $context ) {
    // Only apply to directory (listing) pages. Leave map, dashboard, and featured unchanged.
    if ( 'directory' === $context ) {
        $defaults['posts_per_page'] = 24;
    }
    return $defaults;
}

Example 2: Increase the Maximum Number of Map Pins

Map queries have a built-in limit on how many property pins are loaded (controlled by the theme option
wp_estate_map_max_pins, which defaults to 200). If you have a large number of properties
and want to display up to 500 pins on the map, you can increase this default:

<?php
/**
 * Allow up to 500 property pins on map pages instead of the default 200.
 *
 * Note: Loading more pins means more data transferred to the browser.
 * Test performance with your actual property count before increasing this value too high.
 *
 * Add this code to your child theme's functions.php file.
 */
add_filter( 'wpestate_query_2026_context_defaults', 'my_child_more_map_pins', 10, 2 );
function my_child_more_map_pins( $defaults, $context ) {
    // Only apply to map pin queries.
    if ( 'map' === $context ) {
        $defaults['posts_per_page'] = 500;
    }
    return $defaults;
}

Example 3: Change the Default Sort Order for Featured Widgets

Featured property widgets use sort order code 0 by default, which shows featured
properties first, then sorts by date. If you want featured widgets to sort by newest first
(order code 1) instead:

<?php
/**
 * Sort featured widget properties by newest first instead of the default featured-first order.
 *
 * Sort order codes:
 *   0 = featured-first (default)   1 = newest     2 = price ascending
 *   3 = price descending           4 = oldest     5 = bedrooms ascending
 *   6 = bedrooms descending        7 = size asc   8 = size descending
 *
 * Add this code to your child theme's functions.php file.
 */
add_filter( 'wpestate_query_2026_context_defaults', 'my_child_featured_newest_first', 10, 2 );
function my_child_featured_newest_first( $defaults, $context ) {
    if ( 'featured' === $context ) {
        $defaults['order'] = 1;
    }
    return $defaults;
}

Important Notes

  • This filter changes defaults only, not forced values. If a page template,
    shortcode, or search form explicitly passes a value for the same key, that explicit value will
    override the default you set here. If you need to force a value that cannot be overridden by
    callers, use the wpestate_query_2026_params filter instead.
  • Context-specific overrides are already applied. For example, when the context is
    'map', the fields key is already set to 'ids' and
    no_found_rows is already set to true before your filter fires. You can
    still change these values in your callback if needed.
  • Always return the $defaults array. If your callback does not return
    the array, the query will receive null instead of defaults and will fail.
Technical: Actions and filters

Related Articles

  • How to Add Custom Field Filters to Property Queries
  • How to Map Custom Search Form Fields to Query Parameters
  • How to Inspect or Replace Query Results After Execution
  • How to Modify the Final WP_Query Arguments

Help Categories

  • 18Agent, Agency & Developers
  • 5Blog Posts & Blog Lists
  • 38Elementor Shortcodes Built-In
  • 45FAQ
  • 15Footer
  • 5Getting Started
  • 37Header
  • 2IDX & MLSImport
  • 6Installation & Setup
  • 23Installation FAQ
  • 23Maps & Location Settings
  • 21Multi-Language Third Party Plugins
  • 6Other Third party Plugins
  • 19Pages
  • 4Payments & Monetization
  • 20Property Lists, Categories & Archive
  • 36Property Pages & Layouts
  • 31Search & Filtering
  • 162Technical how to | Custom Code Required
  • 8Technical: Actions and filters
  • 6Technical: Child Theme
  • 86Theme Options & Global Settings
  • 6Translations & Languages
  • 16WPBakery Shortcodes
  • 51WPResidence / WPEstate CRM
  • 50WPResidence 5.0 Documentation
  • 8WPResidence Elementor Studio
  • 50WPResidence Translate Plugin

Join Us On

Powered by WP Estate - All Rights Reserved
  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API