Skip to main content
100%

Gist 08a85737c01bc51262bd481fbef6eabc

✓ Published0🌍 Public
KKopylovVitalik
Last edited Apr 7, 2020
Created on Apr 7, 2020

This example demonstrates a WordPress search behavior that automatically redirects to a single post when a search query returns exactly one result. The code uses WordPress hooks, specifically `add_action` with `template_redirect`, and checks the global `$wp_query` object to verify the post count. If the condition is met, it calls `wp_redirect()` with the permalink of that post and halts execution with `die`. The implementation relies on WordPress core APIs rather than external visualization libraries, showcasing a practical server-side logic pattern for improving search user experience.

AI-generated description

Similar vizzes