SearchWP

Available since: 1.0.8

searchwp_load_posts

View Parameters »

By default SearchWP returns an array of WordPress Post objects when performing searches. If you’re extending SearchWP and only want the IDs you can use this filter.

Example: Use this filter to conditionally return Post IDs instead of Post objects based on the search arguments, add the following to your active theme’s functions.php:

<?php
function my_maybe_searchwp_load_posts( $loadPosts, $args ) {
// print_r( $args ); // uncomment this line to see the engine arguments
return false; // return only post IDs
}
add_filter( 'searchwp_load_posts', 'my_maybe_searchwp_load_posts', 10, 2 );
view raw gistfile1.php hosted with ❤ by GitHub

Parameters

Parameter Type Description
$loadPosts Boolean

Whether to load Post objects

$args Array

Array of arguments to be passed to the search algorithm