admin管理员组

文章数量:1122846

I want to add another filter box to my admin "pages" screen, let's call it search2.

I want to be able to filter the results that I searched to be limited to only pages that contains search2 in the post_content. I've added the box and I can get the input to my function, but I can't figure out what to change in the query. I want this to work in the admin page whether or not 's' is empty & I don't want it to change what's in the 's' field because I want these to be able to be two different strings.

I'm adding the filter to parse_query() and my function looks like:

public function modifyFilterQuery($query){
    global $pagenow;
    $search2_filter = filter_input(INPUT_GET, 'search2_filter', FILTER_SANITIZE_FULL_SPECIAL_CHARS);

    if (true === in_array($post_type, ['page', '', ''], true) && 'edit.php' === $pagenow) {
        if (false === empty($search2_filter)) {
            //What Should I do here? Something like:
            //$query->set(?);
            //?
        }
    }

    return $query;
}

I want to add another filter box to my admin "pages" screen, let's call it search2.

I want to be able to filter the results that I searched to be limited to only pages that contains search2 in the post_content. I've added the box and I can get the input to my function, but I can't figure out what to change in the query. I want this to work in the admin page whether or not 's' is empty & I don't want it to change what's in the 's' field because I want these to be able to be two different strings.

I'm adding the filter to parse_query() and my function looks like:

public function modifyFilterQuery($query){
    global $pagenow;
    $search2_filter = filter_input(INPUT_GET, 'search2_filter', FILTER_SANITIZE_FULL_SPECIAL_CHARS);

    if (true === in_array($post_type, ['page', '', ''], true) && 'edit.php' === $pagenow) {
        if (false === empty($search2_filter)) {
            //What Should I do here? Something like:
            //$query->set(?);
            //?
        }
    }

    return $query;
}
Share Improve this question asked Apr 11, 2024 at 19:29 user18102663user18102663 213 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

There is only one parameter that will filter your results to posts that contain a value in the content, s aka search, but doing so would break the search box. Unless you write code that on save updates a flag to indicate if the post contains that in its post content you can't have both

本文标签: queryHow to use parsequery() to add an additional filter based on content to page search