Skip Navigation

[Resolved] How can I get the views "loop" to skip if the template returns nothing

This support ticket is created 4 years, 9 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.

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by PaulS4783 4 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#1487851

hidden link

I have a Custom Type "Vehicles" and a Custom Field "Sold" (checkbox).
If the "Sold" checkbox is true (eq "1") then the Views Loop Item returns nothing, based on ToolSet Conditional logic.

I have a Loop configured to return a table of 3 columns.
The problem is that the Loop doesn't skip entirely.
I get a blank space in the table when the vehicle is "Sold".
Apparently the loop still returns a blank <td></td>

How can I address this?
Is it possible to wrap part of the Loop editor in conditional tags?

This is the View Loop:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<table width="100%" class="stock-page wpv-loop js-wpv-loop">
	<wpv-loop wrap="3" pad="true">
		[wpv-item index=1]
		<tr>
			<td>
				[wpv-post-body view_template="loop-item-in-all-vehicles"]
			</td>
		[wpv-item index=other]
			<td>
				[wpv-post-body view_template="loop-item-in-all-vehicles"]
			</td>
		[wpv-item index=3]
			<td>
				[wpv-post-body view_template="loop-item-in-all-vehicles"]
			</td>
		</tr>
		[wpv-item index=pad]
			<td></td>
		[wpv-item index=pad-last]
			<td></td>
		</tr>
	</wpv-loop>
	</table>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

TBH I don't understand what these mean:
[wpv-item index=pad]
[wpv-item index=pad-last]
The documentation says:
index=pad will be executed if there are no records left to output, but the number of records is not a multiple of the loop wrap value.
index=pad-last will be executed for the last item in the loop if are no records left to output, but the number of records is not a multiple of the loop wrap value.
I don't understand "multiple of the loop wrap value".

And this is the Loop Item template:

[wpv-conditional if="( $(wpcf-sold) ne '1' )"]
<h4 id="stock-page"><i class="fas fa-tag"></i>  [format-currency num='[types field='price' output="raw" format='FIELD_VALUE'][/types]'] JPY</h4>
<p><a href="[wpv-post-url]">[wpv-post-featured-image size="large" class="centered-and-cropped"]</a></p>
<h5>[types field="make"][/types] [types field="model"][/types]</h5>
<h5>([types field="year-of-manufacture"][/types])</span><h5>
<h5><i class="fas fa-road"></i>  [format-currency num='[types field='mileage-km' format='FIELD_VALUE'][/types]'] KM</h5>
<p><a class="more" href="[wpv-post-url]"><button>[wpml-string context='ToolSet']More Information ... [/wpml-string]</button></a></p>
[/wpv-conditional] 
#1488547

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

First of all - After checking to debug the information you shared with us, I found that you are using outdated Toolset plugins. We always recommend running your site with the latest stable release plugin version.

*** Please make a FULL BACKUP of your database and website.***
Could you please update ALL Toolset plugins to it's latest officially released version. You can download the latest plugin release from your accounts page:
=> https://toolset.com/account/downloads/

Regarding your original query: I don't understand "multiple of the loop wrap value".
So, lets say, you have If you have created a 4 column grid (that means it will display 4 columns/records in one row) and you have total 9 records to display.
- so, first row will display the 4 records
- Second row will display the 4 records
- on the third row, the final row, the last result (9th item) is in the first column, and on columns 2, 3, and 4 are empty as we do not have any records to dispaly, as we have a total of 9 records.
-- So, on last row (the thrid row) index=pad would output for columns 2 and 3 and index=pad-last would output for column 4 (the last column)

Here is the Doc where [wpv-item] shortcode is explained with its index attribute values:
=> https://toolset.com/documentation/user-guides/views/digging-into-view-outputs/#loop-shortcode-wpv-item-and-the-index-parameter
=> https://toolset.com/documentation/user-guides/views/view-layouts-101/

More info:
=> https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-item

#1488639

Thats a good explanation about
[wpv-item index=pad]
[wpv-item index=pad-last]

BUT it does absolutely nothing to help me solve the main issue of this ticket.

Please go back and read it again.

#1488645

Minesh
Supporter

Languages: English (English )

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

Ok - so lets talk on your original issue.

As I understand, you want to display only items that are NOT sold, correct? If yes:
Can I check your setup? for that you need to share access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1489687

You can close this ticket.

The solution was a simple one.

Just put:

'Custom field string equals "1" ' /* vehicle sold*/
OR
'Custom field string does not equal "1" ' /*vehicle not sold*/

into the query parameters at the top of the View page.

No need to use conditional logic in this case.