-
Notifications
You must be signed in to change notification settings - Fork 64
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
Convert search criteria into a filter #126
Open
peussen
wants to merge
4
commits into
parisholley:master
Choose a base branch
from
peussen:prevent_multiple_main_query_issues
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8a07893
Allow users to add their own conditions to when a query should be tri…
peussen e554c94
Allow users to add their own conditions to when a query should be tri…
peussen 258cef8
Merge branch 'prevent_multiple_main_query_issues' of github.com:marty…
peussen 9cb9d98
Remove check i needed for my site, which should not be merged into th…
peussen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,13 @@ abstract class AbstractArchive{ | |
function __construct(){ | ||
add_action('pre_get_posts', array(&$this, 'do_search'), 100); | ||
add_action('the_posts', array(&$this, 'process_search')); | ||
add_filter('elasticsearch_should_query_' . $this->get_filter_name(),array($this,'filter_singular_query'),10,2); | ||
add_filter('elasticsearch_should_query_' . $this->get_filter_name(),array($this,'filter_frontend_main_query'),20,2); | ||
} | ||
|
||
function do_search($wp_query){ | ||
if(!$wp_query->is_main_query() || is_admin() || $this->attempted){ | ||
|
||
if ( !Config::apply_filters('should_query_' . $this->get_filter_name(),true,$wp_query)) { | ||
return; | ||
} | ||
|
||
|
@@ -75,6 +78,28 @@ function sort_posts($a, $b){ | |
return array_search($b->ID, $this->ids) > array_search($a->ID, $this->ids) ? -1 : 1; | ||
} | ||
|
||
|
||
function filter_frontend_main_query($allowed,$wp_query) { | ||
return $allowed && $wp_query->is_main_query() && !is_admin(); | ||
} | ||
|
||
function filter_singular_query($allowed,$wp_query) { | ||
return $allowed && !$this->attempted; | ||
} | ||
|
||
/** | ||
* Removes any namespaces and transforms the class name into lowercase for use in filters | ||
* | ||
* @return string | ||
*/ | ||
function get_filter_name() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not a fan of having filters depend on class names, as they can change at any time. better to maybe put common logic in abstract and have child classes call it instead with its own name |
||
$class = trim(get_class($this), '\\'); | ||
if ($last_separator = strrpos($class, '\\')) { | ||
$class = substr($class, $last_separator + 1); | ||
} | ||
return strtolower($class); | ||
} | ||
|
||
abstract function facets($wp_query, $existing); | ||
} | ||
?> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the purpose of $allowed or adding the extra functions? seems like it would be easier to just do:
$valid = !(!$wp_query->is_main_query() || is_admin() || $this->attempted);
$valid = Config::apply_filters('should_query', $valid);