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.