{"id":4510,"date":"2022-04-01T15:43:28","date_gmt":"2022-04-01T12:43:28","guid":{"rendered":"https:\/\/creativethemes.com\/blocksy\/?post_type=documentation&amp;p=4510"},"modified":"2022-04-01T15:43:28","modified_gmt":"2022-04-01T12:43:28","slug":"offset-blocksy_posts-shortcode","status":"publish","type":"documentation","link":"https:\/\/creativethemes.com\/blocksy\/docs\/code-snippets\/offset-blocksy_posts-shortcode\/","title":{"rendered":"Offset [blocksy_posts] Shortcode"},"content":{"rendered":"\n<p>Many of you have asked for a way to skip some articles from the [ blocksy_posts ] shortcode. Here&#8217;s the snippet for this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>add_filter('blocksy:general:shortcodes:blocksy-posts:args', function ($args) {\t\n  $args&#91;'offset'] = 5;\n  return $args;\n} );<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"change-instances\">Bonus! Shortcode instances<\/h2>\n\n\n\n<p>You can also use shortcode instances, and offset them independently.<\/p>\n\n\n\n<p>Simply insert your shortcode like [ blocksy_posts shortcode_instance=&#8221;instance-1&#8243; ], then control it like this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>add_filter(\n\t'blocksy:general:shortcodes:blocksy-posts:args',\n\tfunction ($query_args, $shortcode_args) {\n\t\tif (\n\t\t\t! isset($shortcode_args&#91;'shortcode_instance'])\n\t\t\t||\n\t\t\t$shortcode_args&#91;'shortcode_instance'] !== 'instance-1'\n\t\t) {\n\t\t\treturn $query_args;\n\t\t}\n\n\t\t\/\/ Update $query_args as you wish\n\n\t\treturn $query_args;\n\t},\n\t10, 2\n);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Controlling Multiple Instances<\/h2>\n\n\n\n<p>You can also control multiple instances with a minimal amount of code. Just like this!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>add_filter(\n  'blocksy:general:shortcodes:blocksy-posts:args',\n  function ($query_args, $shortcode_args) {\n    if (! isset($shortcode_args&#91;'shortcode_instance'])) {\n      return $query_args;\n    }\n\n    \/\/ &#91;blocksy_posts shortcode_instance=\"instance-1\"]\n    if ($shortcode_args&#91;'shortcode_instance'] === 'instance-1') {\n      $query_args&#91;'offset'] = 5;\n    }\n\n    \/\/ &#91;blocksy_posts shortcode_instance=\"instance-2\"]\n    if ($shortcode_args&#91;'shortcode_instance'] === 'instance-2') {\n      $query_args&#91;'offset'] = 10;\n    }\n    \n    \/\/ &#91;blocksy_posts shortcode_instance=\"instance-3\"]\n    if ($shortcode_args&#91;'shortcode_instance'] === 'instance-3') {\n      $query_args&#91;'offset'] = 15;\n    }\n\n    return $query_args;\n  },\n  10, 2\n);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Many of you have asked for a way to skip some articles from the [ blocksy_posts ] shortcode. Here&#8217;s the snippet for this. Bonus! Shortcode instances You can also use shortcode instances, and offset them independently. Simply insert your shortcode like [ blocksy_posts shortcode_instance=&#8221;instance-1&#8243; ], then control it like this. Controlling Multiple Instances You can [&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-4510","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\/4510","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=4510"}],"version-history":[{"count":0,"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/documentation\/4510\/revisions"}],"wp:attachment":[{"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/media?parent=4510"}],"wp:term":[{"taxonomy":"doc_categories","embeddable":true,"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/doc_categories?post=4510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}