Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPBカップ
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

WordPressの検索クエリーで1つしか一致しない場合に自動リダイレクトする

WordPressでブログを検索すると、検索結果に1つの項目しか表示されないことがある。サイトの構成にもよりますが、これはユーザーが探していた項目であるはずです。あるユーザーから、検索クエリーの結果が1つしか一致しない場合、その投稿にリダイレクトする方法はないかという質問がありました。この投稿では、検索クエリーで1つしか一致しなかった場合にユーザーを投稿にリダイレクトする方法を紹介します。

すべてテーマのfunctions.phpファイルを開き、以下のスニペットを貼り付けるだけです。

[cbk1]

この機能を期待していないユーザーもいるでしょう。そのため、彼らを驚かせてしまうかもしれません。

情報開示 私たちのコンテンツは読者支援型です。これは、あなたが私たちのリンクの一部をクリックした場合、私たちはコミッションを得ることができることを意味します。 WPBeginnerの資金源 をご覧ください。3$編集プロセスをご覧ください。

アバター

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

究極のWordPressツールキット

ツールキットへの無料アクセス - すべてのプロフェッショナルが持つべきWordPress関連製品とリソースのコレクション!

Reader Interactions

7件のコメント返信を残す

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Casey Lessard says

    Worked for me. I run a local search engine using WordPress and I have been trying to find this solution for some time. Does exactly as described. Thank you so much!

  3. Eric says

    I want to make it so when some searches a specific phrase it redirects to an easter egg, like if someone searches “I see dead people” specifically it’ll redirect them to a URL I can define.

  4. Nebulas Website Design says

    Thanks for this piece of code it made my client very happy and I didn’t thnk it could be done. However it’s not working for us we are using the Relevanssi search plugin should it work with this?

  5. carlos says

    What if I want to redirect any search query to the most relevant post no matter what the number of posts the search returns? I’d really like to be able to do that.

返信を残す

コメントありがとうございます。すべてのコメントは私たちのコメントポリシーに従ってモデレートされ、あなたのメールアドレスが公開されることはありませんのでご留意ください。名前欄にキーワードを使用しないでください。個人的で有意義な会話をしましょう。