2

I want to use the edit-tags.php search function with multiple term id's. For example, if i type into the searchbox something like this: #1245&6832, it should display these two terms in the results table(WP_Terms_List_Table).

I tried to use the pre_get_posts action to get access to the query that is running for the search, but this is just showing me an "empty" query:

add_action('pre_get_posts', 'filter_terms_by_ids' );

function filter_terms_by_ids( $wp_query ) {
    global $pagenow;

    if($pagenow == 'edit-tags.php' && $_GET['s']):
        print_r($wp_query->query_vars);
    endif;

}

My idea is to check the $_GET['s'] and if # is the first character, i can modify the query to only include these terms in the search:

if ('#' == substr($_GET['s'],0,1))
1

It's easy to implement. All you need is your own hook for get_terms_args filter:

add_filter( 'get_terms_args', 'wpse8170_get_terms_args', 10, 2  );
function wpse8170_get_terms_args( $args, $taxonomies ) {
    if ( !in_array( 'post_tag', $taxonomies ) ) {
        return $args;
    }

    $matches = array();
    if ( empty( $args['search'] ) || !preg_match( '/^\#(.*)$/', $args['search'], $matches ) ) {
        return $args;
    }

    if ( count( $matches ) == 2 ) {
        $args['search'] = '';
        $args['include'] = array_filter( array_map( 'intval', explode( '&', $matches[1] ) ) );
    }

    return $args;
}
  • Thanks, works as excepted, i just needed to change post_tag to my taxonomy name. – passatgt Jan 11 '13 at 17:39
  • @passatgt u r welcome – Eugene Manuilov Jan 11 '13 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.