Skip Navigation

[Resolved] Delete Taxonomy in a View Query

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 7 replies, has 2 voices.

Last updated by adi-iskandarB 6 years, 9 months ago.

Assisted by: Noman.

Author
Posts
#549798

I'm building a simple dropbox-ish web app in our intranet using Views, whereby each folder is a taxonomy. What I'm trying to accomplish is the ability to delete Folders/Taxonomy when there are no items in query.

Naturally, I looked at [wpv-no-items-found] in the Output editor. However, it seems the query couldn't fetch any taxonomy information if there are no items within the queried taxonomy.

I tried the following but to no avail,

[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[wpml-string context="wpv-views"][get_terms]
[wpml-string context="wpv-views"][wpv-post-taxonomy type="folder" format="slug"][/wpml-string]
[/wpv-no-items-found]

[get_terms] is a custom shortcode to see if I can get any info on the taxonomy programatically via php, but I can't seem to make any of it work.

If Toolset suite has any shortcode to remove/delete taxonomy, this would be great. Otherwise, I'm open to using custom shortcode.

Appreciate your help, thanks.

#549844

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Adi,

Thank you for contacting Toolset Support. Do you want to remove taxonomy terms OR want to remove entire taxonomy (e.g. Categories taxonomy section) for the post type?

Any taxonomy term that ho no post assigned to it, would be automatically hide as per WP native settings.

- If you want to exclude a taxonomy term then this might be helpful:
https://toolset.com/forums/topic/how-to-exclude-one-taxonomy-from-all-but-its-own-archive/#post-397028

- https://toolset.com/documentation/programmer-reference/views-filters/
View API filters that can be used for this purpose can be from these:
wpv_filter_taxonomy_query
wpv_filter_taxonomy_post_query
wpv-after-display-taxonomy
wpv-before-display-taxonomy

Thank you

#550009

Hi Noman, thanks for responding. I meant to delete a taxonomy term. For instance, I have a taxonomy called 'Folder'. Then I have a cred form that allows a user to upload files (new posts) and also create new folders in the frontend, e.g. 'folder A', 'folder B', etc. So a user can add more files to any of these folders. At the same time, I have a cred link to allow the user to delete any of these posts. Eventually, there will be a scenario where the user would not require a folder anymore. So here, I'm trying to make a button to allow the user to delete a folder with the logical condition if the folder is empty.

In my view for taxonomy 'folder', it traverses through all existing folders and lists out all files belonging to that folder as a radio (even empty ones, but will say 'no items found'). In the results, I'm able to get the folder's data (url, ID, etc). But for the ones which does not have any files, it doesnt return any value. I understand why it returns empty because it has no posts to query. But I should still be able to get around this since its traversing through the taxonomy.

Can you show some pointers?

If only I can get hold of the slug or ID in the filter layout but I'm only limited to %%NAME%% and %%COUNT%%.

Appreciate your assistance.

#550086

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Show empty terms.png

- I assume that you are using Taxonomy View for this. To Show empty terms you can change this View settings in Query Options >> Uncheck this “Don't show empty terms” -- please see attached screenshot.

- This will then display all terms in the View loop, which will allow you to list Empty terms & get the ID of the empty terms using this shortcode:

 [wpv-taxonomy-id] 

- Then later after doing above, you can hide empty terms using Conditional Output like this:

[wpv-conditional if="( '[wpv-taxonomy-post-count]' gte '1' )"]
[wpv-taxonomy-id] - [wpv-taxonomy-title]
[/wpv-conditional]

OR if you want to hide it or do something using code, you will use this hook:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv-display-taxonomy-2

I hope these pointers will help you in right direction. Thank you

#550242
Folder-wo-files.jpg
Folder-w-files.jpg

Hi Noman,

The idea is to put a link to delete an empty term, not hide it. I've uploaded some screens to show what I'm trying to achieve.

At the very least, I appreciate your help how I can get term slug for terms with no posts associated to it. The reason why I'm interested to get the term slug is so that I can use php shortcode to delete the empty term. But if cred has a direct option to accomplish this then that'll be great.

Hope this is more clear.

#550293

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

ok I am checking few things at my end and will let you know how to get slug. Thank you

#550303

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello,

Yes I understand that you want to delete empty terms and not hide them. Basically what I was explaining that you can get ID of empty term and then do delete function on it. Right now your approach would be like this:

- To get the slug of empty terms use this shortcode [wpv-taxonomy-slug] (not the [wpv-post-taxonomy] ).
- Then write your own custom function or code or shortcode that will perform deletion of this empty term, because once you get the term slug you can do whichever WP function you want to perform on it.

We do not have this delete option in Toolset. This should be done through custom code and we cannot consult on custom code as this is out of support policy (https://toolset.com/toolset-support-policy/). If you would like you can contact Toolset recommended consultants to further discuss the custom approach. We have some recommended list of service providers here if you would like to take a look: https://toolset.com/consultant/

Thanks

#551583

Hi Noman,

Unfortunately I'm using post type view.

Anyway, I managed to resolve the situation by using ajax. I was able to retrieve the term slug from the URL and perform some ajax function to delete the empty terms.

Thanks for your responses.

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.