{"id":4595,"date":"2022-04-15T10:26:26","date_gmt":"2022-04-15T07:26:26","guid":{"rendered":"https:\/\/creativethemes.com\/blocksy\/?post_type=documentation&amp;p=4595"},"modified":"2022-04-15T10:26:26","modified_gmt":"2022-04-15T07:26:26","slug":"modify-the-related-posts-queries","status":"publish","type":"documentation","link":"https:\/\/creativethemes.com\/blocksy\/docs\/code-snippets\/modify-the-related-posts-queries\/","title":{"rendered":"Modify the Related Posts queries"},"content":{"rendered":"\n<p>In some cases, you might wish to modify the criteria on how the Related Posts module pulls in its posts. We have created two example filters, which accept standard WordPress queries. These help you modify the criteria on how Related Posts are pulled in.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">blocksy:related-posts:query-args<\/h3>\n\n\n\n<p>This filter computes query arguments, such as sorting options.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>add_filter('blocksy:related-posts:query-args', function ($args) {\n    $args&#091;'order'] = 'DESC';\n    \/\/ Other custom args\n\n    return $args;\n});<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">blocksy:related-posts:query<\/h3>\n\n\n\n<p>This filter modifies the logic completely and lets you make advanced posts pulls in accordance to your rules.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>add_filter('blocksy:related-posts:query', function ($query) {\n    global $post;\n\n    return new WP_Query(&#091;\n        \/\/ Logic for computing the related based on the current post...\n        'posts_per_page' =&gt; 5,\n    ]);\n});<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In some cases, you might wish to modify the criteria on how the Related Posts module pulls in its posts. We have created two example filters, which accept standard WordPress queries. These help you modify the criteria on how Related Posts are pulled in. blocksy:related-posts:query-args This filter computes query arguments, such as sorting options. blocksy:related-posts:query [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_acf_changed":false,"footnotes":""},"doc_categories":[125],"class_list":["post-4595","documentation","type-documentation","status-publish","hentry","doc_categories-code-snippets"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6}},"acf":[],"_links":{"self":[{"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/documentation\/4595","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/documentation"}],"about":[{"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/types\/documentation"}],"author":[{"embeddable":true,"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/comments?post=4595"}],"version-history":[{"count":0,"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/documentation\/4595\/revisions"}],"wp:attachment":[{"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/media?parent=4595"}],"wp:term":[{"taxonomy":"doc_categories","embeddable":true,"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/doc_categories?post=4595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}