Skip Navigation

[Résolu] View Tag not filtering /detecting current post type

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:

Setup a view filter by "detecting the post type" of posts in current archive page.

Solution:

In your case, it needs custom codes, see details here:

https://toolset.com/forums/topic/view-tag-not-filtering-detecting-current-post-type/#post-1132547

Relevant Documentation:

This support ticket is created Il y a 5 années et 6 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 – 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)

Marqué : 

This topic contains 17 réponses, has 2 voix.

Last updated by Akhil Il y a 5 années et 6 mois.

Assisted by: Luo Yang.

Auteur
Publications
#1132516

Hi nigel.

from here :https://toolset.com/forums/topic/tag-widget-current-post-type/

i thought the issue is solved as i just need to load the view inside widget , but i was wrong,
this is my current tag widget output , its not detecting the post type , its displaying all post types.

ive set the filter
Taxonomy filter : Select posts with taxonomy: Blog Categories the same as the page where this View is shown.

the code is very straight forward

  [wpv-if evaluate="'[wpv-post-taxonomy type="blog-tag" format="slug"]' != '' "]
  <div class="article_meta_tag">
  <i class="fal fa-tags"></i> [wpv-post-taxonomy type="blog-tag" separator=""]  
  </div> 
  [/wpv-if]

what could be the issue pls, thanks.

#1132547

Hi,

I assume we are talking about the widget "TAGS" of this page:
hidden link

If it is wordpress built-in "Tag cloud" widget, It is expected result: it will output all terms in taxonomy "Tag".

And the parameter "post_type" of filter hook widget_tag_cloud_args won't work in your case, that parameter is for return a tag link with URL parameter "post_type=my-cpt-slug", see wordpress document:
https://developer.wordpress.org/reference/functions/wp_tag_cloud/#source

line 691:

$link = get_edit_term_link( $tag->term_id, $tag->taxonomy, $args['post_type'] );

In your case, it needs custom codes, I suggest you setup your own custom shortcode, query terms only belongs to current post type, and display this shortcode in a text widget, see similar thread:
https://wordpress.stackexchange.com/questions/118861/getting-taxonomy-terms-used-by-custom-post-type

For setup shortcode, please check this document:
https://developer.wordpress.org/reference/functions/add_shortcode/

#1132550

Sorry luo i didnt post the page issue , its this hidden link .

its a widget views -

#1132569
post-type.JPG

Thanks for the details, the URL you mentioned above seems to be a term "foods" archive page.
I can see the view's result is "No items found".
I assume you are going to display posts of specific custom post type.

If it is, please try these:
1) Create a wordpress archive with Views plugin:
https://toolset.com/documentation/user-guides/creating-wordpress-custom-post-archives/

2) in section "Loops Selection", choose option "Categories", click "Edit" button, then you can specific the custom post types as you want, see screenshot post-type.JPG

#1132631

totally wrong thing youre looking at.

my issue is the WIDGET on the sidebar. Nowhere i mention "archive ".

1. the widget tag is displaying 3 loops of the codes, not sure why.

Do i need to create view for each post type using filter and load into widget-wp view ?
or some adjustment needed to detect the cpt ?

#1133167

Is it wordpress built-in "Tag cloud" widget?
If it is, please check my first answer:
https://toolset.com/forums/topic/view-tag-not-filtering-detecting-current-post-type/#post-1132547
You might need to consider custom codes, please let me know if you need assistance to setup the custom shortcode. thanks

#1133185

No its not, its toolset widget.

#1133189

i realise my mistake too. its not auto detecting the taxonomies. not custom post type. post type is main : blog.

update : somehow its displaying logically now. but the issue that remain is double loop repeating of the view.

pls let me know if you still unclear ill try to explain further.

#1133190

How do you setup the view? please provide your website credentials in below private message box

#1133210

Please have a look at your view "Blog Tag View", it is a post view, query posts of post type "RISE Blogs", and display the terms assigned to each post:
[wpv-post-taxonomy type="rise-blog-tag" separator=""]

Since there are two posts in the result, so it is expected result:
double loop repeating of the view

There isn't such kind of built-in feature, you will need to consider custom codes.

#1133213

Hi, do you mean the view will loop depending on number of post of the post type blog ?
is there something wrong with my filter :
Select posts with taxonomy: Blog Categories the same as the page where this View is shown

or should i set to taxonomies view instead ? if no, How do i stop this ?

#1133215

Luo, is there any other way to achive this ? Pls share. thanks

#1133252

Q1) do you mean the view will loop depending on number of post of the post type blog ?
Yes, as I mentioned above, since there are two items in the result, so view's loop will be triggered twice, it will conduct other problem: duplicated term links, for example,
Post 1 with term A + term B
Post 2 with term B + term C

You post view will output "term B" twice.

Q2) or should i set to taxonomies view instead ?
The taxonomy view won't work in your case, as I mentioned above, there isn't such kind of built-in feature within Views plugin

Q3) is there any other way to achive this ?
It needs custom codes, I have shared a link in my first answer:
Getting taxonomy terms used by custom post type
https://wordpress.stackexchange.com/questions/118861/getting-taxonomy-terms-used-by-custom-post-type

But your case is much complicated than above example, I suggest you check it with our Toolset contractors:
https://toolset.com/contractors/

#1133253

Hi, any update on this ? hope to close this ticket soon.

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