{"id":14093760,"date":"2021-02-24T06:04:40","date_gmt":"2021-02-24T06:04:40","guid":{"rendered":"https:\/\/wordpress.org\/support\/?post_type=topic&#038;p=14093760"},"modified":"2021-02-24T06:09:24","modified_gmt":"2021-02-24T06:09:24","slug":"help-with-implementation","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/help-with-implementation\/","title":{"rendered":"Help With Implementation"},"content":{"rendered":"<p>Hello,<\/p>\n<p>I installed your plugin with the hopes that I could use the &#8220;Load More&#8221; function into an existing template that I have but I have not been able to executed it properly.<\/p>\n<p>I already have a template called related.php which calls related category posts to every single post on the site. The template recognizes the category of each posts.<\/p>\n<p>I wanted to add a &#8220;Load More&#8221; button at the end of the template to load the next round of related posts by category, but everything I have tried does not work, produces PHP errors or comes out in a garbage format.<\/p>\n<p>The template I have works great, again all I want is to be able to insert  a working code at the end of it that will allow your plugin to display a working &#8220;Load More&#8221; button that will display another batch of related posts when you click on it.<\/p>\n<p>I hope you can help.<\/p>\n<p>Here is a sample of the template code:<\/p>\n<pre><code>\n&lt;div class=&quot;relatedpost-container&quot; role=&quot;navigation&quot;&gt;\n&lt;h2 class=&quot;relatedpoststitle&quot;&gt;&lt;?php printf( __(&#039;You are going to love these:&#039;, &#039;theme-nacho&#039;)) ?&gt;&lt;\/h2&gt; \t\t\t\t\n\n&lt;?php\n\/\/function to get related post having codition inside\nfunction get_related_post($postID){\n\t\t\n$tags = wp_get_post_tags($postID);\n$foundPosts = 0;\n$excludes=[$postID];\n\t\t\t\nif ($tags) {\n$tag_ids = array();\nforeach($tags as $individual_tag) $tag_ids[] = $individual_tag-&gt;term_id;\n\t\t\t\n$args=array(\n&#039;tag__in&#039; =&gt; $tag_ids,\n&#039;post__not_in&#039; =&gt; array($postID),\n&#039;showposts&#039;=&gt;12,\n&#039;ignore_sticky_posts&#039;=&gt;1\n);\n\t\t\t\n$my_query = new WP_Query($args);\n$foundPosts = $my_query-&gt;found_posts;\n\t\t\t\nif( $my_query-&gt;have_posts() ) {\nwhile ($my_query-&gt;have_posts()) : $my_query-&gt;the_post();\n$excludes[]=$my_query-&gt;post-&gt;ID; \n\t\t\t\t\t\nget_template_part( &#039;loop&#039;, get_post_format() ); \n\t\t\t\t\t\t \nendwhile;\n}\nwp_reset_query();}\n\t\t\t\nif ($foundPosts &lt;12){\n$remainingPosts = 12- $foundPosts;\nget_category_posts($postID, $remainingPosts, $excludes);\n}\n\t\t\t\n}\n\nfunction get_category_posts($postID, $remainingPosts, $excludes){\n\n$catArgs = array(\n&#039;category__in&#039; =&gt;  wp_get_post_categories($postID), \n&#039;showposts&#039; =&gt; $remainingPosts,\n&#039;post__not_in&#039; =&gt; $excludes\n);\n\t\t\t\t\t\t\t\t\t\t\n$cat_post_query = new WP_Query($catArgs);\n$foundPosts = $cat_post_query-&gt;found_posts;\n\t\t\t\nif( $cat_post_query-&gt;have_posts() ) {\n\t\t\t\t\t\nwhile ($cat_post_query-&gt;have_posts()) : $cat_post_query-&gt;the_post();\n$excludes[]=$cat_post_query-&gt;post-&gt;ID; \n\t\t\t\t\t\t\nget_template_part( &#039;loop&#039;, get_post_format() ); \n\t\t\t\t\t\t\t \nendwhile;\n}\nwp_reset_query();\n\nif ($foundPosts &lt; $remainingPosts){\n$stillRemaing = $remainingPosts-$foundPosts;\n\t\t\t\t\nget_latest_posts($excludes, $stillRemaing);}\n }\n\nfunction get_latest_posts($excludes, $stillRemaing){\n\t\n$latestPost = array(\n\t&#039;showposts&#039; =&gt; $stillRemaing,\n\t&#039;post__not_in&#039; =&gt; $excludes,\n\t&#039;post_type&#039; =&gt; &#039;post&#039;,\n\t&#039;posts_per_page&#039; =&gt; $stillRemaing,\n\t&#039;offset&#039;=&gt;0,\n\t&#039;orderby&#039; =&gt; &#039;post_date&#039;,\n\t&#039;order&#039; =&gt; &#039;DESC&#039;,\n\t);\n$latest_post_query = new WP_Query($latestPost);\n\t\t\nif( $latest_post_query-&gt;have_posts() ) {\nwhile ($latest_post_query-&gt;have_posts()) : $latest_post_query-&gt;the_post(); \n\t\t\t\t\t\nget_template_part( &#039;loop&#039;, get_post_format() ); \n\t\t\t\t\t\t  \nendwhile;\n}\nwp_reset_query();\n\t}\n\necho get_related_post($post-&gt;ID); ?&gt;\n \n&lt;\/div&gt;\n<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-14093760","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/14093760","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/14093760\/revisions"}],"predecessor-version":[{"id":14093767,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/14093760\/revisions\/14093767"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=14093760"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}