当搜索词中省略复数('s')时如何创建单词数组以忽略

时间:2018-10-04 11:38:13

标签: php wordpress

我是一名代码新手,目前正在尝试学习所有可能的知识。我整理了一些脚本,以在wordpress的搜索查询中省略“ s”。但是,我希望在某些单词上忽略此功能。我将如何创建阵列来做到这一点?谢谢

    import { Component, OnInit } from '@angular/core';
    import { DataSharingService } from '../service/DataSharingService';
    import { LoginComponent } from '../login/login.component';

    @Component({
      selector: 'app-dashboard',
      templateUrl: './dashboard.component.html',
      styleUrls: ['./dashboard.component.css'],
      providers: [DataSharingService, LoginComponent]
    })
    export class DashboardComponent implements OnInit {
    @ViewChild(LoginComponent) loginComponent: LoginComponent
      constructor(private dataSharingService: DataSharingService) { }

      ngOnInit() {
        this.dataSharingService.currentData.subscribe(data => {
          console.log(data)
        });
      }

      authorize(appName:string): void {
        console.log(this.loginComponent.getApiKey())
      }
    }

1 个答案:

答案 0 :(得分:0)

适合将来希望这样做的任何人。我解决了-希望对您有所帮助! :)

function mySearchFilterFunction($query) {
  if(!is_admin() && $query->is_main_query() && $query->is_search) {
     //### Words to skip
  $skip_words = array('diaries', 'stylus');

      //### Get the search term
  $search_term = trim(strtolower($query->get('s')));

    //### Check if the last letter of the search term is an S
    //### Also check to see if the word is in the skip word array
  if(substr($search_term, -1) == 's' && !in_array($search_term, $skip_words)){
      $search_term = substr($search_term, 0, -1);
  }

  //### Set the search term
  $query->set('s', $search_term);
  }
}