DEV Community

Cover image for Batch Post
Forest Hoffman
Forest Hoffman

Posted on

Batch Post

The Batch Post WordPress plugin gives authors the ability to generate numerous posts from a template post. Using the plugin's custom shortcode, portions of both the title and the body of the template post can be indicated as content that should change through the generation process.

On a regular basis, Rob Schwartz needs to create a set of 10-50 posts with a little variance between each post. This is quite tedious to do manually, and that's where the Batch Post plugin comes into play! Using Batch Post, Rob can create a template, indicate where he'd like the title and content to change, specify any meta data (categories, tags, etc.) that should be applied to the batch, and create as many posts as he needs.

The batch creation process also saves time by overriding the previous batch's posts as needed. That is, if the batch is going to create posts that already exist, they will be deleted and re-created. The posts' slugs are compared to prevent permalink issues.

When a batch is being created, the template post is parsed for instances of the bpauto shortcode. The shortcode itself can be used in two ways:

  1. Default, e.g. [bpauto]
  2. With an offset, e.g. [bpauto offset=1]

The offset argument for the shortcode accepts either a positive or negative offset to the number given to each post based on it's position in the batch.

If the batch template has a post title of ID15-1[bpauto] and the batch size is equal to 5, the result would be:

Post Title Example

Metabox Example

Alternatively, if the batch template's post title was ID15-1[bpauto offset=1], a batch of 5, the result would be:

Post Title Example

Metabox Example

With a unique choice of template title, the batch posts can be linked to each other. For example, consider this post template:

Post Title

ID15-1[bpauto]

Post Body

<video src="example.com/wp-content/uploads/2018/02/id15-1[bpauto].mp4"></video>

<a href="example.com/id15-1[bpauto offset=1]"><button>Next Video</button></a>

This template is using both the default form of the shortcode as well as providing an offset (+1).

With a batch size of 5, the above template will generate the following for the first post:

Post Title

ID15-101

Post Body

<video src="example.com/wp-content/uploads/2018/02/id15-101.mp4"></video>

<a href="example.com/id15-102"><button>Next Video</button></a>

...and for the second:

Post Title

ID15-102

Post Body

<video src="example.com/wp-content/uploads/2018/02/id15-102.mp4"></video>

<a href="example.com/id15-103"><button>Next Video</button></a>

...and so on.

Top comments (0)