When working on third-party plugins or a purchased theme, we may encounter a situation where we need to attach an existing taxonomy (created by someone else) to a custom post type we’ve created (in our case, “fruits” — see this article).

Order website or plugin development for WordPress, website development on the Laravel, Symfony, or Yii2 framework…

When working on third-party plugins or a purchased theme, we may encounter a situation where we need to attach an existing taxonomy (created by someone else) to a custom post type we’ve created (in our case, “fruits” — see this article).

As an example, let’s review a small piece of code that implements a tree with fruits attached to it. In this case, the 'tree' is our custom taxonomy, and 'fruit' is a custom post type used to define fruits with all their parameters (color, taste, etc. — these are not discussed in this article).

In reality, determining this is quite simple. For example, if we are on an archive page (where hooks like is_archive, is_tag, etc. are triggered), we can use the following approach: