{"id":1036,"date":"2013-08-24T10:05:45","date_gmt":"2013-08-24T10:05:45","guid":{"rendered":"http:\/\/musilda.cz\/?p=1036"},"modified":"2013-08-24T10:05:45","modified_gmt":"2013-08-24T10:05:45","slug":"jak-presmerovat-vyhledavani-na-clanek-kdyz-je-nalezen-jeden-vysledek","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/jak-presmerovat-vyhledavani-na-clanek-kdyz-je-nalezen-jeden-vysledek\/","title":{"rendered":"Jak p\u0159esm\u011brovat vyhled\u00e1v\u00e1n\u00ed na \u010dl\u00e1nek, kdy\u017e je nalezen pouze jeden v\u00fdsledek"},"content":{"rendered":"\n
Pokud pou\u017e\u00edv\u00e1te vestav\u011bn\u00e9 vyhled\u00e1v\u00e1n\u00ed ve WordPressu a nem\u00e1te na to nainstalovan\u00fd n\u011bjak\u00fd plugin, m\u016f\u017ee se v\u00e1m st\u00e1t, \u017ee vyhled\u00e1v\u00e1n\u00ed zobraz\u00ed jen jeden v\u00fdsledek. V tomto p\u0159\u00edpad\u011b by bylo vhodn\u011bj\u0161\u00ed, p\u0159esm\u011brovat vyhled\u00e1v\u00e1n\u00ed rovnou na nalezen\u00fd v\u00fdsledek.<\/p>\n\n\n\n\n\n\n\n
Do na\u0161eho magick\u00e9ho souboru vlo\u017e\u00edme n\u00e1sleduj\u00edc\u00ed k\u00f3d:<\/p>\n\n\n\n
add_action('template_redirect', 'redirect_single_post');\nfunction redirect_single_post() {\n if (is_search()) {\n global $wp_query;\n if ($wp_query->post_count == 1) {\n wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );\n }\n }\n}\n<\/pre>\n\n\n\nPokud je v\u00fdsledek pouze jeden, zobraz\u00edme p\u0159\u00edmo onen v\u00fdsledek.<\/p>\n","protected":false},"excerpt":{"rendered":"
Pokud pou\u017e\u00edv\u00e1te vestav\u011bn\u00e9 vyhled\u00e1v\u00e1n\u00ed ve WordPressu a nem\u00e1te na to nainstalovan\u00fd n\u011bjak\u00fd plugin, m\u016f\u017ee se v\u00e1m st\u00e1t, \u017ee vyhled\u00e1v\u00e1n\u00ed zobraz\u00ed jen jeden v\u00fdsledek. V tomto p\u0159\u00edpad\u011b by bylo vhodn\u011bj\u0161\u00ed, p\u0159esm\u011brovat vyhled\u00e1v\u00e1n\u00ed rovnou na nalezen\u00fd v\u00fdsledek.<\/p>\n","protected":false},"author":1,"featured_media":8624,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-1036","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-snippety"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/1036"}],"collection":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/comments?post=1036"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/1036\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media\/8624"}],"wp:attachment":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media?parent=1036"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=1036"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=1036"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}