Published on July 20, 2021

Get post count given CPT, Taxonomy while excluding current item

Sridhar Katakam

This members-only tutorial provides the steps to define a custom function that returns that number of items of the given Custom Post Type other than the current one when any singular page of the CPT is being viewed that belong to the same taxonomy term(s) as the current item.

This can then be used, for example, with Oxygen's Dynamic Data > PHP Function Return value feature to ensure that a Section having a Repeater for showing "related" CPT items gets output only if there is at least one matching post.

Step 1 - Custom function

Install and activate Code Snippets plugin.

Go to Snippets > Add New.

Title: [Function] Get post count given CPT, taxonomy while excluding current item

Code:

This is a premium members-only content.

To view the rest of the content, please sign up for membership ($47/month or $499 one-time).

Already a member? Log in below or here.

tagschevron-leftchevron-rightchainangle-rightangle-upangle-downfolder-omagnifiercrossmenuchevron-downarrow-right