Skip Navigation

[Résolu] Display Term Fields on Archive Page

This support ticket is created Il y a 7 années et 7 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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

Supporter timezone: Europe/Madrid (GMT+02:00)

This topic contains 6 réponses, has 3 voix.

Last updated by jeffreyS-5 Il y a 7 années et 7 mois.

Assisted by: Juan.

Auteur
Publications
#436224
Screen Shot 2016-09-14 at 2.59.22 PM.png
Screen Shot 2016-09-14 at 2.51.32 PM.png

I am trying to: Display term fields of a custom taxonomy on an archive page

I visited this URL: the support forum

I expected to see: a solution

Instead, I got: nothing addressing this exact problem

I have custom posts with hierarchical taxonomy, where the parents is called Collection and the child taxonomies can be called anything (i.e. blue, red, green). I have added term fields to the taxonomies (i.e. Collection Name, Collection Image)

I have a Layout that includes an archive cell to display all the posts of a specific type that are tagged with a specific collection (i.e. displays only posts tagged blue)

the URLs looks like
hidden link
hidden link

On the same layout, I have added a new view, where I am trying to display the term fields.. but I can't seem to create the right filter to show just the term fields for the current taxonomy term
(i.e. currently it shows: Collection Name, Collection Image for every single collection) INSTEAD, I want to filter to show just the terms for current page (i.e. just the terms for taxonomy blue)

I've tried creating a query filter to filter by taxonomy filters and the collection fields, but nothing seems to work. (attached image).

I have a feeling that I could use the termmeta field filter, but I just don't know what to write. For example, I think the URL parameter would work if I knew what the url parameter was for a 'child' taxonomy.

Thanks in advance!

#436383

Nigel
Supporter

Languages: Anglais (English ) Espagnol (Español )

Timezone: Europe/London (GMT+01:00)

Hi Jeff

I haven't gone to the trouble (yet) of trying to replicate your set-up to confirm how to do this, but the key for the view you are using to show the term fields is one of context.

When using the standard category archive pages, for example, you could add a view to that page with a query filter which takes the page where this view is displayed as its context, so that it knows the category to which you are referring when displaying term meta fields.

Likewise when looping through category terms, a query filter could reference the current item in the loop to identify the category to which the term meta fields related.

If you are using the standard category archive pages then you have the context in place to simply use the Types or Views shortcodes to output your term fields without the need to create a new View, as the context is the archive which is being displayed.

See https://toolset.com/documentation/views-shortcodes/#wpv-taxonomy-field, which will output the raw data for the field, or you can use Types to render the formatted fields, e.g. if you have an image for your term meta.

Does that make sense?

If not then let me know and I will try to replicate your set up and show you it working.

#436933

Nigel
Supporter

Languages: Anglais (English ) Espagnol (Español )

Timezone: Europe/London (GMT+01:00)

Hi Jeff

I set up a test site where I replicated the key features from your site, and I'm happy to report I have it working, so let me quickly run through the steps.

- I have a CPT called "Performances".
- I have a custom Taxonomy called "Collections" which is assigned to Performances.
- I have added custom taxonomy fields of "Collection Name" and "Collection Image" to the Collections taxonomy.
- I created some sample content for each of the above.
- I created a View that I have called "Collection terms" which I am going to use to display the Collection Name and Collection Image on my collection archive pages.

This View is a taxonomy view, which displays Collections, and it has a query filter which is a Taxonomy term filter where "Taxonomy is set by the page where this View is inserted". So when we are on a collection archive page such as mysite.com/collection/outside it will only return the "outside" term from our taxonomy.

In the loop output section I can use the "Fields and Views" button to insert the shortcodes to output my term custom fields for the current term (e.g. the image for "outside").

My somewhat crude loop output looks like this:

<wpv-loop>
	<p>Term name: [types termmeta='collection-name'][/types]</p>
	[types termmeta='collection-image' size='full' align='none'][/types]
</wpv-loop>

Now I put this together in my Layout. I think you know how to do this already.

Just one observation, when looking at your site, the Collection Archive you created, you have added a Query filter to "Select posts with taxonomy: Collections slug in one of those set by the URL parameter wpvcollection" but I think this may be redundant. On a taxonomy archive page the posts that appear on that page are for the term which appears in your url in the format you have already described, e.g. mysite.com/collection/outside, you don't need to add an additional filter for that.

So I have a layout called "Collections archive" which is used to customise the Collections archive.

In my simple test site I have just two rows.

The first is a cell where I insert my Collection terms View.

The second has the Layouts archive cell for the Collection Archive.

When I visit mysite.com/collection/outside I see the collection image and name, followed by the list of matching performance posts.

Hopefully if you reproduce the above you'll see the same.

#436941

Hi Nigel,

What you've described is the same setup I have.
But it still shows the termmeta fields for more than one collection. It looks like it's basing which termmetas to show by the performances listed on that page.

i.e. if the performance is tagged with more than one collection, it will show the termmeta for all those collections

It doesn't look like it's basing the termmeta off the specific taxonomy term archive

Did you tag a performance with more than one collection?

Thanks,
Jeff

#437078

Nigel
Supporter

Languages: Anglais (English ) Espagnol (Español )

Timezone: Europe/London (GMT+01:00)

Hi Jeff

You are right.

I tried tagging a performance post with more than one term and it meant multiple terms being returned by the taxonomy view.

We are together at our annual conference at the moment and it was a good opportunity for me to speak to our lead developer Juan about this.

The behaviour is not what you or I are expecting, but it came as no surprise to Juan. When you select "set by the page where this view is inserted", it doesn't work as expected on archive pages. The global $post object on such an archive page refers not to the page itself but to the first item returned in the loop on that page, so the taxonomy terms returned will depend on what terms the first post is tagged with.

If you have posts tagged with multiple terms what you are aiming to do is not going to work, currently. Juan has asked that I assign this ticket directly to him so that he can handle it as a feature request.

In the meantime you are limited to assigning single terms (or to contriving some ordering means so that the first post which appears in the archive only has a single term).

I'm sorry I don't have a ready solution for you.

#437138

Juan
Supporter

Timezone: Europe/Madrid (GMT+02:00)

Hi Jeff

This is Juan here, lead developer for Views.

As Nigel is explaining above, the main reason this is not working for you is that we do not have such a feature like the one that you are trying to use (but I have good news anyway below). Shortly, when on a taxonomy archive page, if you add a View that lists taxonomy terms, there is no option to get data from the current one which archive you are visiting.

I understand the confusion with the query filter that states "get data from the current page", but in this context a "page" is a single post, so it is supposed to work on single frontend pages, not on archives.

Now, the good news. In your description, you said that you are using a View because you want to display the term fields for the term which archiveyou are visiting. Thinking out of the box, I am considerin gthat maybe a View here is not the best of the ideas, because you are trying to use it to get just one term and its termmeta. When trying to get just one object and its data, using a View is generally not the best or most straight forward solution.

Now, something that you might not be aware of: when you use a Types shortcode to get a term post field value, inside an archive page for that taxonomy term, you do get the term field value automatically. You do not need a View for it. In fact, the View listing terms of a taxonomy kind of "hijacks" the Types shortcode to force it to display data for each of the terms that this View returns, but the "native" usage for Types term fields is, indeed, inside term archive pages.

I am suggesting you to do the following: instead of putting a View cell to load the term custom fields, could you put just a Visual Editor cell, and fill it with the Types shortcodes that you need, like the one for the term mage field? It should indeed work. And if it dos not, then we do have a problem to debug and solve 🙂

Hope it helps, let me know if you need further assistance.

Regards.

#437572

Hi Nigel + Juan,

Yes, that worked! A far more elegant solution than what I was trying to do.

Thanks very much!

Jeff

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