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

Convert search criteria into a filter #126

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
27 changes: 26 additions & 1 deletion wp/theme/AbstractArchive.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
Copy link
Owner

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);

}

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() {
Copy link
Owner

Choose a reason for hiding this comment

The 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);
}
?>