Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite Scroll: check that search terms exist… #2128

Merged
merged 2 commits into from
May 19, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions modules/infinite-scroll/infinity.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ function body_class( $classes ) {
$disabled = '' === get_option( self::$option_name_enabled ) ? true : false;
if ( ! $disabled || 'click' == self::get_settings()->type ) {
$classes[] = 'infinite-scroll';

if ( 'scroll' == self::get_settings()->type )
$classes[] = 'neverending';
}
Expand Down Expand Up @@ -404,7 +404,7 @@ function get_excluded_posts() {
* @return array
*/
function get_query_vars() {

$query_vars = self::wp_query()->query_vars;
//applies to search page only
if ( true === self::wp_query()->is_search() ) {
Expand All @@ -428,15 +428,15 @@ function get_query_vars() {
* @return bool
*/
function has_only_title_matching_posts() {

//apply following logic for search page results only
if ( false === self::wp_query()->is_search() ) {
return false;
}

//grab the last posts in the stack as if the last one is title-matching the rest is title-matching as well
$post = end( self::wp_query()->posts );

//code inspired by WP_Query class
if ( preg_match_all( '/".*?("|$)|((?<=[\t ",+])|^)[^\t ",+]+/', self::wp_query()->get( 's' ), $matches ) ) {
$search_terms = self::wp_query()->parse_search_terms( $matches[0] );
Expand All @@ -449,9 +449,11 @@ function has_only_title_matching_posts() {
}

//actual testing. As search query combines multiple keywords with AND, it's enough to check if any of the keywords is present in the title
if ( false !== strpos( $post->post_title, current( $search_terms ) ) ) {
$term = current( $search_terms );
if ( ! empty( $term ) && false !== strpos( $post->post_title, $term ) ) {
return true;
}

return false;
}

Expand Down