{"id":1189,"date":"2012-03-29T08:04:18","date_gmt":"2012-03-29T08:04:18","guid":{"rendered":"http:\/\/www.vishmax.com\/en\/?p=1189"},"modified":"2012-05-19T10:38:47","modified_gmt":"2012-05-19T10:38:47","slug":"how-to-show-wordpress-related-posts-without-a-plugin","status":"publish","type":"post","link":"https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/","title":{"rendered":"How to Show WordPress Related Posts without a Plugin"},"content":{"rendered":"<p>Here is a good code which allows you to display related posts from WordPress tags. For example if you have posts with tags like mobile phones, Samsung and Lg then the below code will compare and display posts which have at least one similar tag.It is very useful in a WordPress theme development because we want to keep visitors within the site and increase page views. So just copy the bellow snippet into your WordPress template where you want to show related posts, it is better to show related posts just below current post. Have a nice blogging&#8230; <\/p>\n<pre lang=\"php\">\r\n<?php\r\n\/\/ Snippet for displaying related posts in WordPress using Tags\r\n$tags = wp_get_post_tags($post->ID);\r\nif ($tags) {\r\n\t$tag_ids = array();\r\n\tforeach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;\r\n\r\n\t$args=array(\r\n\t\t'tag__in' => $tag_ids,\r\n\t\t'post__not_in' => array($post->ID),\r\n\t\t'showposts'=>5, \/\/ You can set the number as you like to display\r\n\t\t'caller_get_posts'=>1\r\n\t);\r\n\t$my_query = new wp_query($args);\r\n\tif( $my_query->have_posts() ) {\r\n\t\techo '<h3>Related Posts<\/h3><ul>';\r\n\t\twhile ($my_query->have_posts()) {\r\n\t\t\t$my_query->the_post();\r\n\t\t?>\r\n\t\t\t<li>\r\n\t\t\t<a href=\"<?php the_permalink() ?>\" rel=\"bookmark\" title=\"Permanent Link to <?php the_title_attribute(); ?>\">\r\n\t\t\t<?php the_title(); ?><\/a>\r\n\t\t\t<\/li>\r\n\t\t<?php\r\n\t\t}\r\n\t\techo '<\/ul>';\r\n\t}\r\n}\r\n?>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here is a good code which allows you to display related posts from WordPress tags. For example if you have posts with tags like mobile phones, Samsung and Lg then the below code will compare and display posts which have at least one similar tag.It is very useful in a WordPress theme development because we [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[44],"tags":[72,49,83],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.2.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Show WordPress Related Posts without a Plugin - Vishmax.com<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Show WordPress Related Posts without a Plugin - Vishmax.com\" \/>\n<meta property=\"og:description\" content=\"Here is a good code which allows you to display related posts from WordPress tags. For example if you have posts with tags like mobile phones, Samsung and Lg then the below code will compare and display posts which have at least one similar tag.It is very useful in a WordPress theme development because we [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/\" \/>\n<meta property=\"og:site_name\" content=\"Vishmax.com\" \/>\n<meta property=\"article:published_time\" content=\"2012-03-29T08:04:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-05-19T10:38:47+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"http:\/\/www.vishmax.com\/en\/#\/schema\/person\/785fa94b56eb17ae7706d30777d6ab93\"},\"headline\":\"How to Show WordPress Related Posts without a Plugin\",\"datePublished\":\"2012-03-29T08:04:18+00:00\",\"dateModified\":\"2012-05-19T10:38:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/\"},\"wordCount\":108,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/www.vishmax.com\/en\/#organization\"},\"keywords\":[\"Code Library\",\"WordPress\",\"WP Snippets\"],\"articleSection\":[\"Labs\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/\",\"url\":\"https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/\",\"name\":\"How to Show WordPress Related Posts without a Plugin - Vishmax.com\",\"isPartOf\":{\"@id\":\"http:\/\/www.vishmax.com\/en\/#website\"},\"datePublished\":\"2012-03-29T08:04:18+00:00\",\"dateModified\":\"2012-05-19T10:38:47+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/www.vishmax.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Show WordPress Related Posts without a Plugin\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.vishmax.com\/en\/#website\",\"url\":\"http:\/\/www.vishmax.com\/en\/\",\"name\":\"Vishmax.com\",\"description\":\"Software Company in Calicut for Web Design and eCommerce\",\"publisher\":{\"@id\":\"http:\/\/www.vishmax.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.vishmax.com\/en\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/www.vishmax.com\/en\/#organization\",\"name\":\"Vishmax.com\",\"url\":\"http:\/\/www.vishmax.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vishmax.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.vishmax.com\/en\/wp-content\/uploads\/2023\/03\/logo-vishmax.png\",\"contentUrl\":\"https:\/\/www.vishmax.com\/en\/wp-content\/uploads\/2023\/03\/logo-vishmax.png\",\"width\":150,\"height\":50,\"caption\":\"Vishmax.com\"},\"image\":{\"@id\":\"http:\/\/www.vishmax.com\/en\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"http:\/\/www.vishmax.com\/en\/#\/schema\/person\/785fa94b56eb17ae7706d30777d6ab93\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vishmax.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e218268870406c917d20b442936d9e68?s=96&d=monsterid&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e218268870406c917d20b442936d9e68?s=96&d=monsterid&r=g\",\"caption\":\"admin\"},\"url\":\"https:\/\/www.vishmax.com\/en\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Show WordPress Related Posts without a Plugin - Vishmax.com","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/","og_locale":"en_US","og_type":"article","og_title":"How to Show WordPress Related Posts without a Plugin - Vishmax.com","og_description":"Here is a good code which allows you to display related posts from WordPress tags. For example if you have posts with tags like mobile phones, Samsung and Lg then the below code will compare and display posts which have at least one similar tag.It is very useful in a WordPress theme development because we [&hellip;]","og_url":"https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/","og_site_name":"Vishmax.com","article_published_time":"2012-03-29T08:04:18+00:00","article_modified_time":"2012-05-19T10:38:47+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/#article","isPartOf":{"@id":"https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/"},"author":{"name":"admin","@id":"http:\/\/www.vishmax.com\/en\/#\/schema\/person\/785fa94b56eb17ae7706d30777d6ab93"},"headline":"How to Show WordPress Related Posts without a Plugin","datePublished":"2012-03-29T08:04:18+00:00","dateModified":"2012-05-19T10:38:47+00:00","mainEntityOfPage":{"@id":"https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/"},"wordCount":108,"commentCount":0,"publisher":{"@id":"http:\/\/www.vishmax.com\/en\/#organization"},"keywords":["Code Library","WordPress","WP Snippets"],"articleSection":["Labs"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/","url":"https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/","name":"How to Show WordPress Related Posts without a Plugin - Vishmax.com","isPartOf":{"@id":"http:\/\/www.vishmax.com\/en\/#website"},"datePublished":"2012-03-29T08:04:18+00:00","dateModified":"2012-05-19T10:38:47+00:00","breadcrumb":{"@id":"https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.vishmax.com\/en\/labs\/how-to-show-wordpress-related-posts-without-a-plugin\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/www.vishmax.com\/en\/"},{"@type":"ListItem","position":2,"name":"How to Show WordPress Related Posts without a Plugin"}]},{"@type":"WebSite","@id":"http:\/\/www.vishmax.com\/en\/#website","url":"http:\/\/www.vishmax.com\/en\/","name":"Vishmax.com","description":"Software Company in Calicut for Web Design and eCommerce","publisher":{"@id":"http:\/\/www.vishmax.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.vishmax.com\/en\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/www.vishmax.com\/en\/#organization","name":"Vishmax.com","url":"http:\/\/www.vishmax.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vishmax.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/www.vishmax.com\/en\/wp-content\/uploads\/2023\/03\/logo-vishmax.png","contentUrl":"https:\/\/www.vishmax.com\/en\/wp-content\/uploads\/2023\/03\/logo-vishmax.png","width":150,"height":50,"caption":"Vishmax.com"},"image":{"@id":"http:\/\/www.vishmax.com\/en\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"http:\/\/www.vishmax.com\/en\/#\/schema\/person\/785fa94b56eb17ae7706d30777d6ab93","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vishmax.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e218268870406c917d20b442936d9e68?s=96&d=monsterid&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e218268870406c917d20b442936d9e68?s=96&d=monsterid&r=g","caption":"admin"},"url":"https:\/\/www.vishmax.com\/en\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.vishmax.com\/en\/wp-json\/wp\/v2\/posts\/1189"}],"collection":[{"href":"https:\/\/www.vishmax.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vishmax.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vishmax.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vishmax.com\/en\/wp-json\/wp\/v2\/comments?post=1189"}],"version-history":[{"count":0,"href":"https:\/\/www.vishmax.com\/en\/wp-json\/wp\/v2\/posts\/1189\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.vishmax.com\/en\/wp-json\/wp\/v2\/media?parent=1189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vishmax.com\/en\/wp-json\/wp\/v2\/categories?post=1189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vishmax.com\/en\/wp-json\/wp\/v2\/tags?post=1189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}