You can use the [[posts]] merge tag to display posts, pages, products, or any other custom post types in any email campaigns that you send via Noptin.

What’s the difference between the [[posts]] merge tag and the [[post_digest]] merge tag?

The two merge tags are identical. The main difference is that the [[post_digest]] merge tag can only be used inside a post-digest campaign whereas a [[posts]] merge tag can be used anywhere.

Another difference is that the [[post_digest]] merge tag only displays posts that were published since the last time the campaign was sent.

Pre-requisites

To follow along with this tutorial, you’ll need to:-

  1. Install the latest version of Noptin.
  2. Install the latest version of the Ultimate Add-ons Pack.

The [[posts]] merge tag is only available if you’re using the Ultimate Add-ons Pack. The following sections contain some examples that you can use.

Filter posts by the post type

By default, Noptin will only display blog posts. You can use the post_type parameter to display pages, products, or any other custom post type.

For example,

The example below will display pages…

[[posts post_type="page"]]

… while this example displays WooCommerce products.

[[posts post_type="product"]]

Filter posts by the author

You can use the following parameters to filter posts by the author.

  • author – displays posts whose author has the specified ID, for example, author=1.
  • author_name – filters posts by the author’s ‘user_nicename‘ – NOT the display name, for example, author_name=admin.
  • author__in – filters posts by several author IDs, for example, author_in=1,3,4.
  • author__not_in – excludes several authors by their IDs, for example, author_not_in=1,3,4

Example,

This merge tag displays posts by the author with user ID 6:-

[[posts author=6]]

The merge tag below is similar to the above but uses the user_nicename instead of the user ID.

[[posts author_name="admin"]]

You can also display posts from several authors as shown in the example below. Note that the author IDs are separated using a comma.

[[posts author__in="1,3,5"]]

You can exclude posts from specific authors as shown below:-

[[posts author__not_in="1,3,5"]]

Filter posts by categories

Important

Only blog posts have categories. All other custom post types use custom taxonomies.

For example,

Product categories in WooCommerce are actually a custom taxonomy known as product_cat.

This means that this section is irrelevant if you’re using your merge tag to display custom post types.

You can display blog posts that have a given category (and any children of that category) by providing the category ID as shown in the example below:

[[posts cat=8]]

This is the same as above except that it ignores child categories:

[[posts category__in=8]]

You can also use the category slug:

[[post_digest category="tutorials"]]

To display blog posts that have several categories, use a comma to separate the category ids as shown below:-

[[posts cat="5,7"]]

This is the same as above except that it does not show posts from any children of these categories:-

[[posts category__in="5,7"]]

You can also use category slugs. The example below will only display blog posts that are EITHER categorized as tutorials OR news.

[[post_digest category="tutorials,news"]]

To display blog posts that have ALL of these categories, use a plus (+) instead of a comma (,). The example below will only display blog posts that are categorized as BOTH tutorials and news.

[[post_digest category="tutorials+news"]]

You can also use the category ID instead of the slug as shown below:

[[post_digest category__and="5,7"]]

To display all blog posts except those from a given category, prefix its id with a minus sign (-). The example below will only display posts from the category with ID 14 and skip those that have either category ID 10 or 29.

[[post_digest cat="-10,14,-29"]]

You can also exclude multiple categories this way:

[[post_digest category__not_in="5,7"]]

Filter posts by tags

Important

Only blog posts have tags. All other custom post types use custom taxonomies.

For example,

Product tags in WooCommerce are actually a custom taxonomy known as product_tag.

This means that this section is irrelevant if you’re using your merge tag to display custom post types.

You can display blog posts that have a given tag as shown in the example below (note that we’re using the tag’s slug):

[[post_digest tag="video"]]

This is the same as above but we’re using the tag’s ID instead of the tag’s slug:

[[post_digest tag_id=5]]

The example below will display blog posts that have EITHER the tags tutorials OR news.

[[post_digest tag="tutorials,news"]]

This is the same as above except that it uses the tags’ IDs instead of slugs.

[[post_digest tag__in="5,7,13"]]

Use a plus (+) instead if you want to display blog posts that have BOTH tags.

[[post_digest tag="tutorials+news"]]

This is the same as above except that it uses the tags’ IDs instead of slugs.

[[post_digest tag__and="5,7,13"]]

You can also display blog posts that do not have any of the two tag ids 3 and 4:

[[post_digest tag__not_in="3,4"]]

Filter posts by custom taxonomies

Noptin allows you to filter posts by custom taxonomies. All you have to do is pass the custom taxonomy name as a parameter key and then pass the term as the parameter value.

For example,

The following merge tag will display products that have the product_cat taxonomy set to hoodies. WooCommerce registers the product category taxonomy as product_cat.

[[post_digest post_type="product" product_cat="hoodies"]]

This is the same as above but we’re using the term’s ID instead by adding ‘_ids‘ to the taxonomy:

[[post_digest post_type="product" product_cat_ids="5"]]

The example below will display products that have EITHER been categorized as hoodies OR tshirts.

[[post_digest post_type="product" product_cat="hoodies,tshirts"]]

This is the same as above except that it uses the terms’ IDs instead of slugs.

[[post_digest post_type="product" product_cat_ids="5,7,13"]]

Append ‘_and' to a taxonomy to display posts that have ALL the terms.

[[post_digest post_type="product" product_cat_and="hoodies,tshirts"]]

This is the same as above except that it uses the terms’ IDs instead of slugs.

[[post_digest post_type="product" product_cat_ids_and="5,7,13"]]

You can exclude multiple terms by appending ‘_not_in‘ to the taxonomy as shown:

[[post_digest post_type="product" product_cat_not_in="hoodies,tshirts"]]

This works the same as the above example except it uses the term IDs instead of slugs:

[[post_digest post_type="product" product_cat_ids_not_in="3,4"]]

Not sure how to find the taxonomy name?

Open the taxonomy’s management page. You’ll see the correct taxonomy name in the URL.

Checking the correct taxonomy name

Filter posts by custom fields

Noptin allows you to filter posts by custom fields as shown in the examples below:-

This example will display posts that have the custom field key ‘color’, regardless of the custom field value:

[[posts meta_key="color"]]

The reverse is also true as shown in the example below which displays posts where the custom field value is red, regardless of the custom field key.

[[posts meta_value="red"]]

Combining the two allows you to check for both the custom field key and value as shown in the below example which only displays posts where the custom field key is color and the custom field value is red.

[[posts meta_key="color" meta_value="red"]]

Use meta_value_num instead of meta_value in cases where the meta value is a number as shown in the example below:-

[[posts meta_key="_price" meta_value_num=20]]

The meta_compare parameter allows you to specify the comparison to use when comparing the meta value as shown in the example below:-

[[posts meta_key="_price" meta_value_num=20 meta_compare="<="]]

Possible values for meta_compare are:-

ComparisonDescription
=(Default) Is equal to
!=Is not equal to
>Is greater than
>=Is greater than or equal to
<Is less than
<=Is less than or equal to
LIKEIs like
NOT LIKEIs not like
INIs in
NOT INIs not in
BETWEENIs between
NOT BETWEENIs not between
EXISTSExists
NOT EXISTSDoes not exist
REGEXPMatches a regular expression
NOT REGEXPDoes not match the regular expression
Possible comparisons you can use with custom fields

The meta_query parameter allows you to filter by multiple custom fields and specify advanced field types such as dates and times.

Important Note:

The meta_query parameter takes an array of meta query arguments arrays (it takes an array of arrays) – you can see this in the examples below.

Each array can contain any (or all) of the following keys.

KeyDescription
keyRequired. The custom field key
valueThe custom field value.
Can be a comma-separated array if compare is 'IN''NOT IN''BETWEEN', or 'NOT BETWEEN'.
You don’t have to specify a value when using the 'EXISTS' or 'NOT EXISTS'
compareOperator to test.
Possible values are ‘=’, ‘!=’, ‘>’, ‘>=’, ‘<‘, ‘<=’, ‘LIKE’, ‘NOT LIKE’, ‘IN’, ‘NOT IN’, ‘BETWEEN’, ‘NOT BETWEEN’, ‘EXISTS’ and ‘NOT EXISTS’.
The default value is ‘=’.
typeCustom field type.
Possible values are ‘NUMERIC’, ‘BINARY’, ‘CHAR’, ‘DATE’, ‘DATETIME’, ‘DECIMAL’, ‘SIGNED’, ‘TIME’, ‘UNSIGNED’.
The default value is ‘CHAR’.
formatYou can provide a format if type is set to either ‘DATE’, ‘DATETIME’, or ‘TIME’.
Allowed meta query keys

Meta query examples:-

Display upcoming events

[[posts post_type="event" meta_query="0[key]=event_date&0[compare]=>=&0[type]=DATE&0[value]=today&0[format]=Ymd"]]

Things to note:-

1. Meta query accepts an array of arrays. 0[key]=event_date is the first array whereas 1[key]=event_town is the second array.

2. You can provide any strtotime readable dates if the field type is either ‘DATE’, ‘DATETIME’, or ‘TIME’.

3. You can pass a date or time format in a format key. You can check the allowed characters here.

Combine multiple custom fields.

[[posts post_type="product" meta_query="0[key]=color&0[value]=blue&0[compare]=NOT LIKE&1[key]=price&1[value]=20, 100&1[compare]=BETWEEN&1[type]=NUMERIC"]]

The above example displays posts that match both custom fields. You can set the relation parameter to “OR” if you only want to match a single parameter from the list.

[[posts post_type="product" meta_query="relation=OR&0[key]=color&0[value]=blue&0[compare]=NOT LIKE&1[key]=price&1[value]=20, 100&1[compare]=BETWEEN&1[type]=NUMERIC"]]

Limit the number of posts to display

By default, Noptin will display a maximum of 10 posts. You can change this as shown below:-

[[posts limit=20]]

The above example displays a maximum of 20 posts whereas the below example displays all posts.

[[posts limit=-1]]

You can also display all posts by disabling pagination as shown below:-

[[posts nopaging=1]]

The limit parameter allows you to skip the first X posts.

For example,

You can skip the first 5 posts as shown below:-

[[posts limit=5 offset=5]]

NOTE:

The limit parameter is ignored when displaying all posts.

Noptin ignores sticky posts by default. You can change this as shown below:-

[[posts ignore_sticky_posts=0]]

Change the order of posts

By default, Noptin will order your posts by the date they were published in descending order. You can change this as shown below:-

[[posts order="ASC"]]

The orderby attribute allows you to order your posts by another field other than the date it was published.

This example shows how to order the posts in your digest email by their title in ascending order.

[[post_digest orderby="title" order="ASC"]]

The orderby attribute accepts one of:-

ValueDescription
IDOrders posts by their ID.
authorOrders posts by their author.
titleOrders posts by their title.
typeOrders posts by their post type.
dateOrders the posts by their creation date.
modifiedOrders the posts by their last modification date.
parentOrders the posts by their parent ID. This is useful if you need to group posts by their parents.
randOrders the posts randomly.
menu_orderOrders pages or custom post types by their page order.
comment_countOrders the posts by the number of comments/popularity.
meta_valueOrders the posts by their meta values. Only use this if you’ve set the meta key attribute.
meta_value_numSimilar to above, but in cases where the meta_value expects a numeric value.
Accepted order by parameters

You can specify several values for the orderby attribute as shown in the next example which orders products by their prices and falls back to their titles in cases where two or more products have the same prices.

[[post_digest post_type="product" meta_key="_price" orderby="meta_value_num title" order="DESC"]]