Purpose

Control how Directorist fetches listings on the "All Listings" page by intercepting and modifying the underlying WP_Query arguments. This powerful hook gives full flexibility over pagination, filtering, ordering, visibility, and custom conditions.


Hook Signature (since v7.4.2)

/**
* Modify the main query args for All Listings.
*
* @param array $args WP_Query-compatible arguments array.
* @param object $listings Instance of Directorist's Listings class.
*/
$args = apply_filters( 'directorist_all_listings_query_arguments', $args, $listings );

Context in Class

Called within Listings::prep_listing_query() (and similar methods), using a default set of query arguments before the final WP_Query is executed. These defaults include:

  • post_type => at_biz_dir

  • post_status => publish

  • paged, posts_per_page, caller, orderby, order

  • Core tax_query for category/location filters

  • Pre-built meta_query for featured status, expiration, price range, etc.


What You Can Customize

You have full control over any part of the query, including:

  1. Pagination & Limits

    • posts_per_page, paged, no_found_rows

  2. Sorting

    • orderby (e.g., title, date, meta_value_num)

    • order (ASC / DESC)

    • Add multi-level ordering using arrays.

  3. Visibility & Status

    • post_status, post__in, post__not_in, author, author__not_in

  4. Filtering by Taxonomy

    • Add/modify $args['tax_query'] elements to filter by location, category, or custom taxonomies.

  5. Filtering by Meta Data

    • Extend $args['meta_query'] with custom key/value comparisons for advanced filtering.

  6. Use-Case Examples

add_filter( 'directorist_all_listings_query_arguments', function( $args, $listings ) {
// Only featured listings
$args['meta_query'][] = [
'key' => '_featured',
'value' => '1',
'compare' => '=',
];

// Order by custom field 'rating_score', descending
$args['meta_key'] = 'rating_score';
$args['orderby'] = 'meta_value_num';
$args['order'] = 'DESC';

// Show 30 per page
$args['posts_per_page'] = 30;

return $args;
}, 10, 2 );

Advanced Use Cases

  • Conditional Filters based on URL, user role, or settings (use $listings->caller, $_GET, or current_user_can()).

  • Exclude temporarily claimed listings by joining core plugin logic with meta flags from Claim Listing extension.

  • Support multi-directory environments by adding a tax_query on directory-type taxonomy.

  • Implement geo-radius queries by integrating custom SQL or meta comparisons before the query runs.


Index of Commonly Modified Keys

Key

Type

Purpose

posts_per_page

int

Number of listings per page

paged

int

Current pagination page

orderby

string/array

Sort field(s)

order

string

Sort direction

post__in

array

Include specific posts

post__not_in

array

Exclude posts

author

int

Filter by author

tax_query

array of arrays

Filter by taxonomy (category/location)

meta_query

array of arrays

Filter by custom fields

meta_key

string

Compare value meta key

meta_value, meta_compare, meta_type

mixed

Meta comparison details


Example 1: Show Listings Only from a Specific Category (e.g., “Restaurants”)

add_filter( 'directorist_all_listings_query_arguments', function( $args, $listings ) {
$args['tax_query'][] = [
'taxonomy' => 'at_biz_dir-category',
'field' => 'slug',
'terms' => ['restaurants'],
];
return $args;
}, 10, 2 );

Example 2: Show Only Listings Added in the Last 7 Days

add_filter( 'directorist_all_listings_query_arguments', function( $args, $listings ) {
$args['date_query'][] = [
'after' => '7 days ago',
];
return $args;
}, 10, 2 );

Example 3: Show Only Listings with Images

add_filter( 'directorist_all_listings_query_arguments', function( $args, $listings ) {
$args['meta_query'][] = [
'key' => '_listing_images',
'compare' => 'EXISTS',
];
return $args;
}, 10, 2 );

Example 4: Randomize Listing Order

add_filter( 'directorist_all_listings_query_arguments', function( $args, $listings ) {
$args['orderby'] = 'rand';
return $args;
}, 10, 2 );

Example 5: Hide Listings from a Specific Author

add_filter( 'directorist_all_listings_query_arguments', function( $args, $listings ) {
$args['author__not_in'] = [15]; // Exclude author ID 15
return $args;
}, 10, 2 );

Example 6: Show Listings by User Role (e.g., Only Listings by 'vendor' Users)

add_filter( 'directorist_all_listings_query_arguments', function( $args, $listings ) {
$vendors = get_users( [ 'role' => 'vendor' ] );
$args['author__in'] = wp_list_pluck( $vendors, 'ID' );
return $args;
}, 10, 2 );

Example 7: Show Listings Marked as “Verified” via a Custom Field

add_filter( 'directorist_all_listings_query_arguments', function( $args, $listings ) {
$args['meta_query'][] = [
'key' => '_is_verified',
'value' => 'yes',
'compare' => '=',
];
return $args;
}, 10, 2 );

Example 8: Show Listings in a Specific Price Range

add_filter( 'directorist_all_listings_query_arguments', function( $args, $listings ) {
$args['meta_query'][] = [
'key' => '_price',
'value' => [100, 500],
'type' => 'NUMERIC',
'compare' => 'BETWEEN',
];
return $args;
}, 10, 2 );

Example 9: Show Only Listings That Are Not Expired

add_filter( 'directorist_all_listings_query_arguments', function( $args, $listings ) {
$args['meta_query'][] = [
'key' => '_listing_expiry_date',
'value' => date( 'Y-m-d' ),
'type' => 'DATE',
'compare' => '>=',
];
return $args;
}, 10, 2 );

Example 10: Sort Listings by a Custom Field First, Then by Date

add_filter( 'directorist_all_listings_query_arguments', function( $args, $listings ) {
$args['meta_key'] = '_priority_score';
$args['orderby'] = [
'meta_value_num' => 'DESC',
'date' => 'DESC',
];
return $args;
}, 10, 2 );