• Resolved Ced

    (@cedriccharles)


    Hello there!

    Thank you for your great plugin!

    In the results page, I need to display the title of the page/post AND the text where the search terms were found. Is there a way to get that part of content with your plugin? How would you do this?

    Thank you in advance,
    Cedric

Viewing 1 replies (of 1 total)
  • Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hello @cedriccharles,

    Thanks for your message.

    The plugin modifies the database query, it is not responsible for displaying the content on the search results page. You have to handle this on your own. Unfortunately, it is not that simple, so I am not able to provide you with a solution.

    As a tip, I can advise you to verify database queries modified by the plugin. This should allow you (when making your own query to the database) to retrieve records from the wp_postmeta table that contain the correct data.

    How to view a database query? Add the following code to the functions.php file in your theme directory:

    add_filter( 'posts_request', function( $sql, $query ) {
    	if ( ! isset($query->query_vars['s'] ) || empty( $query->query_vars['s'] ) ) {
    		return $sql;
    	}
    	echo '<pre>';
    	print_r( $sql );
    	echo '</pre>';
    	exit;
    }, 100, 2 );

    Then run the search and you will get the content of the query. Do this with the plug on and without it, you’ll see the difference. And focus on that part of the query.

    Best,
    Mateusz

Viewing 1 replies (of 1 total)
  • The topic ‘Get/Show content where the terms were found’ is closed to new replies.