Add Filter/Hook to Modify Main Search Query from WPSolr

  • 10 months, 2 weeks ago #34833

    Hi, Can you tell me a filer/hook to modify the default main loop, to modify the results. I want to add a tax query to get some desired results, pre_get_posts not working. Can you help with this. Need to filter data with tax query, I have the query though but need to hook to some event in wpsolr plugin.

    wpsolr
    Keymaster
    10 months, 2 weeks ago #34834

    You can find an example in wpsolr/pro/extensions/geolocation/class-wpsolr-option-geolocation.php, which adds a distance property to the results:

    use wpsolr\core\classes\WPSOLR_Events;
    
    add_action( WPSOLR_Events::WPSOLR_ACTION_POSTS_RESULTS, 'wpsolr_action_posts_results', 10, 2 );
    
    /**
     * @param WPSOLR_Query $wpsolr_query
     */
    public function wpsolr_action_posts_results( $wpsolr_query ) {
    
    	if ( empty( $wpsolr_query->posts ) ) {
    		// No results: nothing to do.
    		return;
    	}
    
    	foreach ( $wpsolr_query->posts as $post ) {
               // Add your property to $post here
    	}
    
    	return;
    }
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.