1. Home
  2. Knowledge Base
  3. Posts Table Pro
  4. Posts Table Pro Shortcode Options
  5. Creating tables with specific posts based on category, taxonomy, custom field, date & more

Creating tables with specific posts based on category, taxonomy, custom field, date & more

Posts Table Pro comes with lots of options for choosing which posts are included in the table. You can display posts with a specific category, tag, post type, status, custom taxonomy term, custom field or date (year, month or day). You can also show or hide specific products from the table based on their ID, and exclude certain categories.

Category

The category option lets you choose which blog post categories are displayed in the table. This applies to blog posts only (i.e. the default, where post_type is set to post). If you’re displaying pages or other custom post types, this option has no effect and you need to use the ‘term‘ option instead (see below).

You should specify the category slug or ID – this can be found under the Posts -> Categories menu in the WordPress dashboard. You can also specify multiple categories to display – either separated by commas or by a plus sign (+). If you use commas it means “posts in this Category A or Category B”. If you use a plus, it means “posts in Category A and Category B”.

For example, to display posts which are in the “design” category or in the “print” category, use: [posts_table category="design,print"]

To display posts which are in the “design” category and in the “print” category, use: [posts_table category="design+print"]

Can I list categories and sub-categories separately?

All posts are displayed in a single list, regardless of whether they are in a parent category or child category.

If you want to list posts separately based on their category, then we recommend adding multiple tables to the page. Each table should list posts from a different category or subcategory. You can divide up the page by adding the category name as a subheading above each table.

Tag

The tag option applies to blog posts only and selects posts based on their tags. If you’re displaying pages or other custom post types, this option has no effect and you need to use the ‘term‘ option instead (see below).

Use the tag slug or tag ID – you can find this in WordPress under the Posts -> Tags menu.

As with categories, you can use one tag or several tags, and you can use commas or a plus sign to denote how tags should be checked. Using commas means “posts with this tag OR that tag”; using the plus sign (+) means “posts with this tag AND that tag”. You can’t mix and match commas and pluses – it’s one or the other.

Example 1: Display posts with tag “awesome”: [posts_table tag="awesome"][/no_shortcodes]

Example 2: Display posts with tags “cool”, “awesome” or “good”: [no_shortcodes][posts_table tag="cool,awesome,good"]

Example 3: posts with tags “cool”, “awesome” and “good”: [posts_table tag="cool+awesome+good"]

Post Type

The post_type option determines which post type (or types) will be displayed in the table. The default is post which will display blog posts. For pages use post_type="page". For attachments you can use post_type="attachment".

For custom post types, you will need to find the ‘slug’ for that post type. The easiest way to do this is to go to the main page for your post type in the WordPress admin and look at the URL. For example, WooCommerce has a ‘products’ post type. If you go to the ‘Products’ menu in the admin, you will notice in the URL in your browser that it looks something like: “../wp-admin/edit.php?post_type=product”. The “product” bit is the post type you need to use. If you’re using Easy Digital Downloads, use post_type="download".

You can also use a list of post types, separated by commas. For example post_type="page,post", will display all blog posts and pages.

Example 1: Display pages: [posts_table post_type="page"]

Example 2: Display Easy Digital Downloads AND WooCommerce products in a table: [posts_table post_type="download,product"]

Example 3: Display a custom post type with the slug ‘members’: [posts_table post_type="members"]

Post Status

The status option displays posts in the table based on their status.

The default status is publish. The other options are draft, pending, future, private or any. Pending posts are those pending a review. Future posts are those scheduled to be published at a future date. Private posts have their visibility set to Private which means they can only be viewed by the post author or other administrators.

You can also use a list of post statuses separated by commas, for example:
[posts_table columns="title,author,categories" post_status="publish,draft"]

Custom taxonomy term

The term option creates a table that only displays posts with the the specified term or terms. The taxonomy that you specify here doesn’t have to be a column in your table.

Use the format: term="<taxonomy slug>:<term slug or ID>". You can enter one term or multiple terms and, as with categories and tags, you can separate terms using a comma (,) or a plus sign (+) to denote whether the posts have any of the terms specified or all of them.

You need to prefix this option with the slug of the taxonomy followed by a colon. For example, to display WooCommerce products that have the product category “coats”, we would use:
[posts_table columns="title,content" post_type="product" term="product_cat:coats"]

To display posts with multiple terms, separate terms by a plus sign (AND) or a comma (OR). If you are selecting from several custom taxonomies, you need to add the taxonomy slug before each term.

The following example will display posts with a document_type of policy or memo:
[posts_table columns="title,content" post_type="document" term="document_type:policy,memo"]

The following example will display posts with a document_type of memo and a document_status of approved:
[posts_table columns="title,content" term="document_type:policy+document_status:approved"]

Custom field

The cf option is used to select posts based on a custom field value. You should use the format cf="<field name>:<field value>" when using this option. As with the above options you can enter one custom field to check, or several, and can separate them using a comma or a plus sign (see categories or tags for more details).

For example, if you are displaying a “car” custom post type and wanted to display cars which are either blue OR are Audis, you would use:
[posts_table columns="title,content" post_type="car" cf="color:blue,make:audi"]

However if you wanted to select the blue Audis (i.e. have color = blue AND make = audi) you would use:
[posts_table columns="title,content" post_type="car" cf="color:blue+make:audi"]

Custom fields added using the Toolset Types plugin

If you’re using Toolset Types to create your custom fields, then you need slightly different syntax to display them in the product table.

Toolset adds wpcf- to the start of the custom field name, so if you create a custom field called ‘color’ with a value of ‘blue’ then the correct syntax will be wpcf-color:blue. This means that if you want to create a table displaying posts with a custom field value of ‘blue’ then you would need to add it as follows:
[product_table cf="cf:wpcf-color:blue"]

Display posts based on when they were published

The following three options control which posts are displayed based on the date they were published.

Year

The year option can be set to limit posts to a specific year. E.g.[posts_table year="2016"]

Month

Selects posts from a specific month. You should use a number here between 1 and 12. You can combine this with the year or day options if you want more fine grained control, e.g.[posts_table year="2015" month="11"]

Day

Selects posts from a specific day in the month. You should use a number between 1 and 31, and as above, you can combine this with the year or month options, e.g.[posts_table month="4" day="25"]

Author

The author option displays posts from a specific author. Use the author ID or a list of IDs.

Example: [posts_table author="1,4"]

Exclude posts

The exclude option can be used to exclude posts or pages from your results based on their post ID. You can enter one ID or a list or IDs.

For example, if you were displaying a table of pages, but wanted to exclude the current page (id=23) which the table is displayed on, you would use:
[posts_table columns="title,content" post_type="page" exclude="23"]

Include posts

The include option can be used to show only specific posts or pages in your table. You can enter one post ID or a list or IDs separated by commas. Note that include and exclude are mutually exclusive – if you set one, the other will be ignored.

Example displaying 4 specific posts: [posts_table include="23,45,67,90"]

Exclude category

The exclude_category option is used to exclude entire categories of posts from your table. You can use category IDs or slugs, and it can be one category or a comma-separated list.

Example: [posts_table exclude_category="3,6"]
Example: [posts_table exclude_category="design"]

Was this article helpful?

Related Articles