Skip Navigation

[Resolved] Display custom taxonomy used by current user?

This thread is resolved. Here is a description of the problem and solution.

Problem:

I have two taxonomies: 1) skill categories and , 2) industry categories.

Skill categories and industry have multiple terms defined in them. Say 20 in skills and 5 in industry.

There are 5 CPTs that use the above two taxonomies.

When users submit custom posts for these 5 CPTs, they add terms from the two custom taxonomies.
I have a overview page for the user where I want to show all the skills and industries tagged by the user along with the count for each term.

Solution:

You might consider below workaround: Nested views:

https://toolset.com/forums/topic/display-custom-taxonomy-used-by-current-user/#post-1884635

Relevant Documentation:

This support ticket is created 4 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 8 replies, has 2 voices.

Last updated by himanshuS 4 years ago.

Assisted by: Luo Yang.

Author
Posts
#1883307

I have two taxonomies: 1) skill categories and , 2) industry categories.
Skill categories and industry have multiple terms defined in them. Say 20 in skills and 5 in industry.
There are 5 CPTs that use the above two taxonomies.
When users submit custom posts for these 5 CPTs, they add terms from the two custom taxonomies.
I have a overview page for the user where I want to show all the skills and industries tagged by the user along with the count for each term.
I tried to do this in view but it does not let me filter taxonomy by current user.

How do I make this happen?

#1883467

Hello,

Since there isn't direct relationship between WordPress user and custom taxonomies, so you won't be able to filter taxonomy by current user, there isn't such kind of feature within Toolset plugins.

As a workaround, you can create a post view:
- Query custom posts
- Filter by post author is current logged-in user:
https://toolset.com/documentation/user-guides/views/filtering-views-query-by-author/
- In view's loop, display post's taxonomy terms.

So you will get all terms from posts created by current logged-in user, but there might be some duplicated terms in the result.

#1884077

Thanks a lot man! That works well.

I have two follow ups:
1) How do I remove the link from the taxonomy tag. I don't want users to click on those at this stage
2) How do I remove duplicate tags and combine them into one and show count next to each tag.

#1884635
term-name.JPG

Q1) If you are using Toolset Single Field block, you can choose "Term name" option, see my screenshot term-name.JPG

Q2) As I mentioned above there isn't such kind of built-in features, you might consider below workaround: Nested views.

For example:
1) Dashboard-> Toolset-> Settings-> General:
in section "Editing experience", enable option "Show both the legacy and Blocks interface and let me choose which to use for each item I build"

2)Dashboard-> Toolset-> Views,
Create two parent taxonomy view:
- Query Terms of taxonomy 1) skill categories and , 2) industry categories
- In view's loop, display below term's name + child post view

3) Child post view:
- Query custom posts
- Filter by:
a) post author is current logged-in user:
https://toolset.com/documentation/user-guides/views/filtering-views-query-by-author/
b) Select posts with taxonomy:
Your custom Taxonomies set by the parent Taxonomy View
https://toolset.com/documentation/user-guides/views/filtering-views-by-taxonomy/

- In view's loop, display post found count shortcode: [wpv-found-count]
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-found-count

4) In the overview page, display both two parent taxonomy view shortcode.

#1887141

Thanks for the guidance here. The view does return value.

To your point: Since there isn't direct relationship between WordPress user and custom taxonomies, so you won't be able to filter taxonomy by current user, there isn't such kind of feature within Toolset plugins.

I will write custom code to get this information but what I need is the table where a taxonomy term is linked to a post. For example, when a publish a project submission CPT through a toolset form that contains taxonomy along with post title and other details, where is this post saved and how are taxonomies linked to that post.

If I know the link between taxonomy term and post, I can then use the user id data in the wp_posts to get terms and term count for the current user.

#1887159
No item found.png

The view you suggested returns no item found for terms where there is no value. Is there a way to remove those terms with no value from the view?

#1887173

This is the code in the parent view. I tried to use a wpv-conditional to test but it did not work.

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv–conditional if="('[wpv-view name ='count-skills-in-project-submissions']' != 'No Items Found')"]No Skill[/wpv–conditional]
[wpv-post-body view_template="loop-item-in-skills-and-skills-count-by-current-user"]([wpv-view name="count-skills-in-project-submissions" limit=10])
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

#1888365

No, the [wpv–conditional] won't work in this case, since Toolset Views will output other HTML tags.

In your case, I suggest you edit the child post view
find and remove the text "No Items Found".

#1893421

My issue is resolved now. Thank you!