Skip Navigation

[Resolved] Looping through post tax terms to create custom url within search result loop

This support ticket is created 7 years, 1 month 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 7 years, 1 month ago.

Assisted by: Nigel.

Author
Posts
#586866

I am trying to: I am using Toolset Views to display search results for the Events and Articles post types. Everything works fine except for I need to hardcode a custom URL for the authors of the Articles in the search results. We have a custom post type of Employees which have a specific page template that we want the authors of articles to link to. The issue is that Views does not allow me to format the taxonomy term url within the post search result loop because that loop already exists. The other thing to keep in mind is that one Article can have many News Authors (taxonomy) attached to them so we need to make sure that they can have their own link to that specific employees page. This is currently what I have in the loop output editor:

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
<div class="row">
<div class="col-md-12">
[wpv-post-body view_template="New and Insights Loop"]
[wpv-item index=1]
<h6>[wpv-post-link]</h6>
<p>Category:
[wpv-if evaluate="'[wpv-post-type]' = 'article'"]Article[/wpv-if]
[wpv-if evaluate="'[wpv-post-type]' = 'event'"]Event[/wpv-if]
</p>
<div class="date-author">
[wpv-post-date] | [wpv-post-taxonomy type="news-author"]
</div>
<p>[wpv-post-excerpt]</p>
[wpv-item index=other]
<h4>[wpv-post-link]</h4>
<p>Category:
[wpv-if evaluate="'[wpv-post-type]' = 'article'"]Article[/wpv-if]
[wpv-if evaluate="'[wpv-post-type]' = 'event'"]Event[/wpv-if]
</p>
<div class="date-author">
[wpv-post-date] | [wpv-post-taxonomy type="news-author"]
</div>
<p>[wpv-post-excerpt]</p>
</div>
</div>
</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]

I want this [wpv-post-taxonomy type="news-author"] to be formatted in such manner:

<!-- wpv-loop-start -->
<wpv-loop>

[wpv-post-taxonomy type="news-author" format="name"]

</wpv-loop>
<!-- wpv-loop-end -->

Link to a page where the issue can be seen: hidden link

hidden link

I expected to see: hidden link

Instead, I got: hidden link

#587068

Nigel
Supporter

Languages: English (English ) Spanish (Español )

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

Hi Tyler

I had some trouble understanding exactly how you have this set up from your question, so I went into your site to take a look.

While I was in there I tried what I thought the solution should be, and I think I now have it how you want it, so let me explain what I did.

You had a second View called Authors to output the links in the required format. It didn't work, and you weren't using it anywhere in any case.

The View was querying the same post types as your main View (Events and Articles), but the purpose of the View is to list the News Author taxonomy terms attached to the posts in your main View. So I changed the View so that it queries the News Author taxonomy and retrieves the terms attached to the "current" post. I formatted the output section as required to produce the list of author links to their employee page.

I then edited your main View and inserted this View into the Loop Output section in place of the wpv-post-taxonomy shortcodes, which generate the undesired link.

If you check what I've done you can hopefully understand how it is working.

There are a couple of provisos.

The nested View is output inside a div, which is a block-level element and means that the list of authors is pushed down to the next line. I added some custom CSS in the CSS editor for the View to fix that, but, it's not working because you have a JavaScript error on the page which is preventing the custom CSS being injected. The error relates to a carousel that doesn't exist on the page. Fixing that will allow the CSS-fix to take effect.

Also, there is a niggling problem with whitespace that I cannot resolve. Where there are multiple authors they are generated as a list, and were separated by commas. But there is a space before the comma that I cannot get rid of, and so I compromised by using an &, where the preceding space is expected, I hope that's okay.