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
:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Parameters
Parameter | Type | Description |
---|---|---|
$loadPosts |
Boolean |
Whether to load Post objects |
$args |
Array |
Array of arguments to be passed to the search algorithm |