Navigation überspringen

[Gelöst] How to get the list of taxonomy ID of a post?

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem: In a View of posts, I would like to display a list of term IDs for all related taxonomy terms.

Solution:
If you know the ID of the Membre post, you can use it to display the related terms in a nested View like this:
- Create a View of this taxonomy, filtered by term, set by the current post (see term-filter.png).
- In this View's loop, output whatever you want to display for each term, like the wpv-taxonomy-title or wpv-taxonomy-link shortcode.
- Create a View of the Membre post type, filtered by post ID, set by a shortcode attribute "ids" (see post-filter.png)
- In the Loop of this View, insert the taxonomy View you just created
- Insert the Membre View somewhere on the site using a shortcode, and add the correct Membre post ID to the "ids" shortcode attribute:

[wpv-view name="Your Membre View Name" ids="12345"]

Replace 12345 with the Membre post ID.

This support ticket is created vor 5 Jahren, 3 Monaten. 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Dieses Thema enthält 4 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Pat vor 5 Jahren, 2 Monaten.

Assistiert von: Christian Cox.

Author
Artikel
#1374923

Pat

Hello,

I have a postype "membre" for which I'm using the standard WordPress taxonomy (category).
I need to retrieve the list of taxonomies that are related to a specific post.
I have already created a Views that list the taxonomies, but I can only list slug, name or url of taxonomies. I have not found the way to return only the ID of the taxonomies.

Can you help on this
Thanks
Pat

#1375127

I have already created a Views that list the taxonomies, but I can only list slug, name or url of taxonomies.
Hi, you can't display the term IDs using a wpv-post-taxonomy shortcode, but you should be able to use the [wpv-taxonomy-id] shortcode in a View of terms. Is the wpv-taxonomy-id shortcode not working correctly inside a View of terms? If not, please copy + paste the code from your Loop Editor here for me to review.

#1375259

Pat

Hi Christian,

Well, the issue I'm facing is a little more complex.

First, I have a user form to subscribe to the site. When the user subscribes, this form creates the user meta, but also, create (with a cred_save_data) a post (postype "membre") in order to have a post that replicates all user info (this is to manage easily the relation between a user and the post taxonomy. For info, this post taxonomy is the standard WordPress taxonomy (that I'm using to define the sports that a user likes.) and is also used for other postypes in the site).

Now, I have a user page where I want to list all sports that he likes. For this, I need to make the following link :
- logged in user => post "membre" => taxonomy linked to this post => display the taxonomies thanks to a Views

Currently, I have defined the Views that display the taxonomies (no issue), and I have also a Views to define the post_id of the post "membre" linked to the logged in user. I just (?) need to retrieve the list of the taxonomies linked to this post "membre" in order to pass them a an argument to the Views that list the taxonomies (term = "id1, id6, ID17" for example)

Hope this clarify the need.
Regards
Pat

#1375553
term-filter.png
post-filter.png

I just (?) need to retrieve the list of the taxonomies linked to this post "membre" in order to pass them a an argument to the Views that list the taxonomies (term = "id1, id6, ID17" for example)
There's nothing built-in to Toolset that will produce a list of term IDs like this, other than a View of terms. If you know the ID of the Membre post, you can use it to display the related terms in a nested View like this:
- Create a View of this taxonomy, filtered by term, set by the current post (see term-filter.png).
- In this View's loop, output whatever you want to display for each term, like the wpv-taxonomy-title or wpv-taxonomy-link shortcode.
- Create a View of the Membre post type, filtered by post ID, set by a shortcode attribute "ids" (see post-filter.png)
- In the Loop of this View, insert the taxonomy View you just created
- Insert the Membre View somewhere on the site using a shortcode, and add the correct Membre post ID to the "ids" shortcode attribute:

[wpv-view name="Your Membre View Name" ids="12345"]

Replace 12345 with the Membre post ID.

Or if you don't want to use Views, you could write a custom shortcode using the wp_get_object_terms API:
https://developer.wordpress.org/reference/functions/wp_get_object_terms/
https://developer.wordpress.org/reference/classes/wp_term_query/__construct/

#1375635

Pat

Hi Christian,

That's perfect. Many thanks.
Pat