Skip Navigation

[Resolved] limiting CPT in taxonomy search

This thread is resolved. Here is a description of the problem and solution.

Problem:

However this taxonomy is shared across several CPTs. How do I narrow that taxonomy search to only search in a specific CPT?

Solution:

There isn't such kind of feature within shortcode [wpv-post-taxonomy], it will output the count value as all posts assigned to the specific term.

In you case, you can consider setup a nested view, for example:

https://toolset.com/forums/topic/limiting-cpt-in-taxonomy-search/#post-1110261

Relevant Documentation:

https://toolset.com/documentation/user-guides/filtering-views-by-taxonomy/

This support ticket is created 6 years, 3 months 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
- 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)

This topic contains 13 replies, has 3 voices.

Last updated by LisaF3065 6 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#1109609

Here at hidden link is a listing of a taxonomy in a widget.

However this taxonomy is shared across several CPTs. How do I narrow that taxonomy search to only search in a specific CPT?

For content selection, I chose taxonomy

I then used a list-group div in the loop editor to group all taxonomies

then in the template view - is "[wpv-post-taxonomy type="sub-topic"] - [wpv-post-taxonomy type="sub-topic" format="count"]"

but i do not see where and how can i limit the taxonomy search to only one specific CPT (stories in this case)

Thanks

#1110261

Hello,

I assume we are talking about this case:
Custom post type "Stories" + "Some other CPT", they both share the same taxonomy "sub-topic", the URL you mentioned above is a single "Stroy" post
hidden link

And you are going to display term's post counts on only "Stroy" posts.

If it is, there isn't such kind of feature within shortcode [wpv-post-taxonomy], it will output the count value as all posts assigned to the specific term.

In you case, you can consider setup a nested view, for example:
1) Parent view list terms of taxonomy "sub-topic"
filter by:
Taxonomy is set by the page where this View is inserted

In view's loop, display the term's title + below child view

2) Child view list posts of Custom post type "Stories", filter by:
Select posts with taxonomy:
sub-topic set by the parent Taxonomy View
https://toolset.com/documentation/user-guides/filtering-views-by-taxonomy/
and display the post counts [wpv-found-count]:
https://toolset.com/documentation/user-guides/views-shortcodes/#vf-155378

#1110590
screenshot2.PNG
screenshot1.PNG

Hello, I've added a child view as instructed

but now it is showing repeated numbers of the count, see screenshot 1

and it is not showing the top 5 (see screenshot 2)... I want to only show 5 taxonomies with the most post count. it should not be showing taxonomies that has no count.

#1111246

Please provide a demo site with the same problem, also point out the problem page URL and view URL, I can setup a demo for you.

#1112017

For the problem:
he item count is repeated...

You can modify the child view:
hidden link
in section "Loop Editor", display the shortcode [wpv-found-count] outsider wpv-loop shortcode
for example:

...
[wpv-items-found][wpv-found-count]
	<!-- wpv-loop-start -->
	<wpv-loop>
	</wpv-loop>
...

See the result here:
hidden link

#1112252

Okay that's better! - but one problem still remains.

You can see in hidden link that the topics are not ordered by the number of posts in the subtopic.

Accessibility has 1 while Alternative Teaching Methods has 2 but Accessibility came first...

I am having the same ordering problem in the list here in hidden link

it's not ordering by number of posts in that sub topic. I do have it set to "Terms of the taxonomy Sub Topics, limit to 5 items ordered by term count, descending"

but it's not looking at only the number of stories, it's looking at the number of sub topics overall. I'm not sure how to fix the ordering.

#1112674

I assume we are talking about the taxonomy view:
hidden link

If you order the result by the "Post count", the view will order the result by "count" column, that column will count all posts of all other post type attached with the terms, for example, you can get the order in wordpress backend:
hidden link

See the column "count" of above page.

More help:
https://developer.wordpress.org/reference/classes/wp_term_query/__construct/

#1113145
Capture2.PNG
Capture.PNG

No - I am referring to the output. It is not ordering by number of posts found.

You can see in the screenshot 1 attached that Accessibility is not last. It should be.

Also in screenshot 2 = it is not ordered by number of posts at all....

So how to fix this so the loop will look at the item count and order by it, not by what is in the taxonomy.

#1114111

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Luo has a day off today. He will get back tomorrow. I will try to help you for now.

The reason why the "Accessibility" term is showing first is that you are filtering your taxonomy view by post count and if you see the data term "Accessibility" and "Alternative Teaching Methods" both have 4 post count. so that is why the term "Accessibility" and "Alternative Teaching Methods" sit one after another ins result.

As you can see both term has post count = 4.

 [3] => WP_Term Object
        (
            [term_id] => 761
            [name] => Accessibility
            [slug] => accessibility
            [term_group] => 0
            [term_taxonomy_id] => 761
            [taxonomy] => sub-topic
            [description] => 
            [parent] => 0
            [count] => 4
            [filter] => raw
        )

    [4] => WP_Term Object
        (
            [term_id] => 764
            [name] => Alternative Teaching Methods
            [slug] => alternative-teaching-methods
            [term_group] => 0
            [term_taxonomy_id] => 764
            [taxonomy] => sub-topic
            [description] => 
            [parent] => 0
            [count] => 4
            [filter] => raw
        )

Now, once you display the term name - you are filtering your result with the nested view to find count but as both terms have same post count 4 and "Accessibility" sits first in the result, it displays accessibility first.

You need to fina a way to filter results when one or more term has same post count.

#1114492

Correct - that is what I'm saying . It's not looking at the found-count number (as displayed in the screenshot above) and sorting by that number. It looks at the subtopic post count instead. That is the wrong number to look at. So. I still need a way to resolve this problem and Minesh's suggestion does not tell me how.

#1114819
acc.JPG

There isn't such kind of built-in feature with such kind of nested view, as I mentioned above:
please have a look to your own website here:
hidden link
see screenshot acc.JPG

Both terms "Accessibility" and "Alternative Teaching Methods" have been assigned to 4 posts, so it conducts the problem:
Accessibility is not last

In the taxonomy view:
hidden link
If you order the result by the "Post count", the view will order the result by "count" column, that column will count all posts of all other post type attached with the terms

There isn't such kind of feature to order the result by post count of child view.

If you insist on it, you might consider custom codes, for example, you can setup another shortcode to achieve what you want:
https://codex.wordpress.org/Function_Reference/add_shortcode

But that is out the range of Toolset support, you can check it with our "Toolset Contractors":
https://toolset.com/contractors/

#1115825

Then should I reverse the nested views to be the child view be listing of taxonomies and then the parent view stories with the taxonomies passed so the ordering can be correct?

#1116027

I don't think reverse the nested views can achieve what you want, this needs custom codes. see details in my previous answer:
https://toolset.com/forums/topic/limiting-cpt-in-taxonomy-search/#post-1114819

#1118408

My issue is resolved now. Thank you!