How to filter by post_parent
-
I have a number of search forms on different pages in my WordPress installation. Based on the page the user is on, these need to filter by the post_parent, which serves as a category in a sense. I have added a hidden field to the search form for ‘post_parent’ so I can pass this value in to the search. This was all working fine with default WP searching, using ‘pre_get_posts’ filter.
I added Relevanssi in order to be able to sort by relevance, and the filtering by post_parent now no longer works. I simply switched ‘pre_get_posts’ to call ‘relevanssi_modify_wp_query’:
function filter_search_by_parent($query) { if ($query->is_search) { if (isset($_GET['post_parent']) && ($_GET['post_parent'] != 0)) { $query->set( 'post_parent', $_GET['post_parent'] ); $query->set('post_type', 'page'); } else { $query->set('post_type', 'post'); } } return $query; } //add_filter('pre_get_posts','filter_search_by_parent'); add_filter('relevanssi_modify_wp_query', 'filter_search_by_parent');
What is the proper way to accomplish this with Relevanssi?
Any help is appreciated.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to filter by post_parent’ is closed to new replies.