Problem:
The customer wants to target and apply different code to specific items in a View loop, specifically targeting items 1-6 with one code and items 7 and beyond with a different code (including adding a data attribute for lazy load).
Solution:
We suggested using the [wpv-loop-index] shortcode along with the [wpv-conditional] shortcode to conditionally apply code to items based on their index within the View loop. The provided example shows how to use these shortcodes to target items with an index less than or equal to 6 with one code and items with an index greater than 6 with another code that includes the lazy load attribute.
For example:
[wpv-layout-start]
[wpv-items-found]
<!-- Target items with index less than or equal to 6 -->
[wpv-conditional if="( '[wpv-loop-index]' le '6')"]
<div class="item">
<!-- Your code for items 1-6 -->
</div>
[/wpv-conditional]
<!-- Target items with index greater than 6 -->
[wpv-conditional if="( '[wpv-loop-index]' gt '6')"]
<div class="item" data-lazy="true">
<!-- Your code for items with lazy load attribute -->
</div>
[/wpv-conditional]
[wpv-no-items-found]
<p>No items found</p>
[/wpv-items-found]
[wpv-layout-end]
Problem:
The customer wants to set a custom field as the featured image for an entire custom post type. They are looking for a solution to establish this custom field globally for each post, as they did not find an existing feature in the documentation that meets this requirement.
Solution:
We informed the customer that there is no built-in feature within Toolset to directly set a custom field as the featured image. However, we provided a workaround involving the following steps:
Use the save_post action hook to trigger a PHP function when a post is saved.
Use the get_post_meta function to retrieve the custom image field value.
Retrieve the remote image file using cURL.
Save the image into the WordPress media library using wp_insert_attachment.
Set the media ID as the post's featured image using set_post_thumbnail.
Additionally, we shared a link to a forum post where a colleague provided a working example of code that runs through all posts of a specific custom post type, assigning a given custom field as the featured image.
The customer noticed that users were able to have multiple photos attached to their profiles in the WordPress Admin, even though only one photo should be allowed. He wanted to ensure that if a user removes their profile photo and resubmits the form, the photo is permanently deleted. Additionally, if a user chooses a new photo, it should replace the existing one.
Solution:
We explained that Toolset Forms does not natively support this feature but provided a workaround using custom code:
1- Use the cred_save_data action hook to trigger a PHP function when a user submits the post form.
2- In the PHP function:
• Retrieve images attached to the current post using get_attached_media.
• Access images stored in the custom repeating image field using get_post_meta.
• Compare these sets of images to identify and remove unused files using wp_delete_attachment.
I have created custom post types named "Offers of the day" using WPBakery Page Builder. After publishing a new post, the page appears boxed rather than full-width, and the post metadata is displayed at the top, which cannot be hidden. Adjusting Bootstrap settings in Toolset has not resolved these issues.
Solution:
Use a CSS code snippet to make the page full-width and hide the post metadata by targeting the unique CSS class generated for the custom post type: