Skip Navigation

[Resolved] How to hide results in Views that are under a certain custom post type?

This support ticket is created 5 years, 11 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/Karachi (GMT+05:00)

This topic contains 7 replies, has 2 voices.

Last updated by StanleyT8485 5 years, 10 months ago.

Assisted by: Waqar.

Author
Posts
#1190860

Tell us what you are trying to do?
I want to hide results in Views that are under a certain custom post type.

What is the link to your site?
Localhost

#1191020

Hi Stanley,

Thank you for contacting us and I'll be happy to assist.

The Toolset Views plugin offers a shortcode "wpv-post-type" ( ref: https://toolset.com/documentation/user-guides/views-shortcodes/#vf-153408 ) which can be used with a conditional block shortcode, to show/hide the results in a view, based on post type.

For example, in the slug of your target post is "books", you can use:


[wpv-conditional if="( '[wpv-post-type]' eq 'books' )"]
Show only if this is a book post type
[/wpv-conditional]

[wpv-conditional if="( '[wpv-post-type]' ne 'books' )"]
Show only if this is not a book post type
[/wpv-conditional]

I hope this helps!

regards,
Waqar

#1192322

Thanks for this, Waqar.

How about hiding a view result based on a parent's post type?

#1192553

Hi Stanley,

Thanks for writing back.

The shortcode "wpv-post-type" ( ref: https://toolset.com/documentation/user-guides/views-shortcodes/#vf-153408 ) accepts "item" attribute, which can be used to specify parent ( either hierarchical or the one in post-relationship ).

You'll find more details on the topic from this guide:
https://toolset.com/documentation/user-guides/views-shortcodes/item-attribute/

regards,
Waqar

#1193494

How would you hide results if their parent is "Companies"?

I tried this and it doesn't work.

[wpv-conditional if="( '[wpv-post-type]' ne '@company.parent' )"]
Show only products that are not under the Company parent post type.
[/wpv-conditional]

Another follow up question, how would you hide the result if the Views is in a table format?

<table class="wpv-loop js-wpv-loop">
	<wpv-loop wrap="4" pad="true">
		[wpv-item index=1]
		<tr>
			<td>
				[wpv-post-body view_template="Loop item in One page order 2019"]
			</td>
		[wpv-item index=other]
			<td>
				[wpv-post-body view_template="Loop item in One page order 2019"]
			</td>
		[wpv-item index=4]
			<td>
				[wpv-post-body view_template="Loop item in One page order 2019"]
			</td>
		</tr>
		[wpv-item index=pad]
			<td></td>
		[wpv-item index=pad-last]
			<td></td>
		</tr>
	</wpv-loop>
	</table>
#1193754

Hi Stanley,

To better guide you around both these questions, I'll need to fully understand two points:

1. Which post types are selected in the view's "Content Selection" settings?

2. What is the relationship between "Products" and "Companies"?

It would help if you could put your website online and share its access details or share screenshots of how the view and the relationship are set up.

(I've set your next reply as private, in case you'd want to share the admin access details)

regards,
Waqar

#1194380

Hi Stanley,

Thank you for sharing further details.

To only show a product, if it is not in a relationship with a company post, you can wrap it inside a conditional block, like this:


[wpv-conditional if="( '[wpv-post-type item='@company_product.parent']' ne 'company' )"]
<div class="featured-image">
  	<a href="[wpv-post-url]">[wpv-post-featured-image size='thumbnail']</a>
	<h3>[wpv-post-link]</h3>
</div>
[/wpv-conditional]

As for your second part of the question, table format for this view won't work, since you'll be filtering out some results based on their relationship. The total number of results returned by the view will be different than the actual number of results shown on the front-end, leaving some empty table cells.

You can structure your results in regular div tags and then add custom CSS code to show the results in a grid format (without the table).

regards,
Waqar

#1195217

My issue is resolved now. Thank you!