{"id":232789,"date":"2023-01-29T11:37:00","date_gmt":"2023-01-29T08:37:00","guid":{"rendered":"https:\/\/wordpress.mediadoma.com\/?p=232789"},"modified":"2023-02-06T11:18:49","modified_gmt":"2023-02-06T08:18:49","slug":"hur-omdirigerar-man-till-det-enda-inlaegget-i-wordpress-soekresultat","status":"publish","type":"post","link":"https:\/\/wordpress.mediadoma.com\/sv\/hur-omdirigerar-man-till-det-enda-inlaegget-i-wordpress-soekresultat\/","title":{"rendered":"Hur omdirigerar man till det enda inl\u00e4gget i WordPress-s\u00f6kresultat?"},"content":{"rendered":"<p><a href=\"https:\/\/wordpress.mediadoma.com\/sv\/hur-laegger-man-till-disqus-om-kommentarer-aer-staengda-i-wordpress\/\" title=\"WordPress\">WordPress<\/a> har en inbyggd s\u00f6kfunktion, och du kan skriva in \/?s=Key efter din wordpress rotplats. Men ibland, om det bara finns ett resultat, t.ex. om anv\u00e4ndaren vet vad den ska s\u00f6ka efter, \u00e4r det b\u00e4ttre att g\u00e5 till det specifika inl\u00e4gget omedelbart utan att visa s\u00f6ksidan. Detta kommer s\u00e4kerligen att f\u00f6rb\u00e4ttra anv\u00e4ndarupplevelsen. Det h\u00e4r \u00e4r en ganska &quot;lycko&quot;-knapp men fungerar bara n\u00e4r det bara finns ett matchat resultat.<\/p>\n<p>S\u00e5 kopiera bara f\u00f6ljande <a href=\"https:\/\/helloacm.com\/the-php-bing-wallpaper-bot-crawler\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">PHP<\/a> -kod i slutet av din WordPress-temanall (b\u00e4ttre att anv\u00e4nda <a href=\"https:\/\/wordpress.mediadoma.com\/sv\/wordpress-barntema-det-enda-du-behoever-veta\/\" title=\"underordnade teman\">underordnade teman<\/a> ), dvs <a href=\"https:\/\/wordpress.mediadoma.com\/sv\/hur-tillaater-jag-bilder-istaellet-foer-url-i-wordpress-kommentarer\/\" title=\"functions.php\">functions.php<\/a>.<\/p>\n<pre><code>add_action('template_redirect', 'redirect_single_post_from_search');\nfunction redirect_single_post_from_search() {\n\u00a0 if (is_search()) { \/\/ if it is a search page\n\u00a0 \u00a0 global $wp_query;\n\u00a0 \u00a0 if ($wp_query-&gt;post_count == 1 &amp;&amp; $wp_query-&gt;max_num_pages == 1) { \/\/ if only 1 result\n\u00a0 \u00a0 \u00a0 wp_redirect( get_permalink( $wp_query-&gt;posts['0']-&gt;ID) ); \u00a0\/\/ go to that page\n\u00a0 \u00a0 \u00a0 exit;\n\u00a0 \u00a0 }\n\u00a0 }\n}<\/code><\/pre>\n<p>Det \u00e4r ett snabbt till\u00e4gg! Inga snygga plugins och det fungerar som en charm!<\/p>\n<p><div id=\"PostUnique_PostSource\" style=\"padding-top: 50px\">Inspelningsk\u00e4lla:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/helloacm.com\" class=\"external external_icon\">helloacm.com<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hur omdirigerar man till det enda inl\u00e4gget i WordPress-s\u00f6kresultat?<\/p>\n","protected":false},"author":1,"featured_media":221243,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[838,848,999,922,807,868],"tags":[1173],"class_list":["post-232789","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-guide-foer-nyboerjare","category-handledningar","category-innehallsmarknadsforing","category-oevrig","category-php-9","category-wordpress-9","tag-affiai-sv"],"_links":{"self":[{"href":"https:\/\/wordpress.mediadoma.com\/sv\/wp-json\/wp\/v2\/posts\/232789","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.mediadoma.com\/sv\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.mediadoma.com\/sv\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/sv\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/sv\/wp-json\/wp\/v2\/comments?post=232789"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.mediadoma.com\/sv\/wp-json\/wp\/v2\/posts\/232789\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/sv\/wp-json\/wp\/v2\/media\/221243"}],"wp:attachment":[{"href":"https:\/\/wordpress.mediadoma.com\/sv\/wp-json\/wp\/v2\/media?parent=232789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/sv\/wp-json\/wp\/v2\/categories?post=232789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/sv\/wp-json\/wp\/v2\/tags?post=232789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}