Offset [blocksy_posts] Shortcode

Many of you have asked for a way to skip some articles from the [ blocksy_posts ] shortcode. Here’s the snippet for this.

add_filter('blocksy:general:shortcodes:blocksy-posts:args', function ($args) {	
  $args['offset'] = 5;
  return $args;
} );

Bonus! Shortcode instances

You can also use shortcode instances, and offset them independently.

Simply insert your shortcode like [ blocksy_posts shortcode_instance=”instance-1″ ], then control it like this.

add_filter(
	'blocksy:general:shortcodes:blocksy-posts:args',
	function ($query_args, $shortcode_args) {
		if (
			! isset($shortcode_args['shortcode_instance'])
			||
			$shortcode_args['shortcode_instance'] !== 'instance-1'
		) {
			return $query_args;
		}

		// Update $query_args as you wish

		return $query_args;
	},
	10, 2
);

Controlling Multiple Instances

You can also control multiple instances with a minimal amount of code. Just like this!

add_filter(
  'blocksy:general:shortcodes:blocksy-posts:args',
  function ($query_args, $shortcode_args) {
    if (! isset($shortcode_args['shortcode_instance'])) {
      return $query_args;
    }

    // [blocksy_posts shortcode_instance="instance-1"]
    if ($shortcode_args['shortcode_instance'] === 'instance-1') {
      $query_args['offset'] = 5;
    }

    // [blocksy_posts shortcode_instance="instance-2"]
    if ($shortcode_args['shortcode_instance'] === 'instance-2') {
      $query_args['offset'] = 10;
    }
    
    // [blocksy_posts shortcode_instance="instance-3"]
    if ($shortcode_args['shortcode_instance'] === 'instance-3') {
      $query_args['offset'] = 15;
    }

    return $query_args;
  },
  10, 2
);
Not the solution you are looking for?

Please check other articles or open a support ticket.