[Résolu] How classic View render repeatable field as post
This support ticket is created Il y a 2 années et 5 mois. 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.
I have repeatable field "related-tools" which is the slug of Woocommerce product. The related-tools is a custom field belong to custom post type 'class', a class may contain several related tools, how can I get the list of the repeatable field and then render them as related product post under the content template. I want to generate using View classic editor.
I capture a sample hidden link there are two products related to this skill, both kp57bl129 and sa209-ks are the SKU and also product slug, I want to display these two products instead of the SKU.
I name the slug for the WooCommerce product the same as the SKU so that customers can simply input the SKU that they are familiar with the product and easy to remember.
add_filter( 'wpv_filter_query', 'wpv_filter_query_func', 1000 , 3 );
function wpv_filter_query_func( $query_args, $view_settings ) {
// process if specific view
if ( ( isset($view_settings['view_id']) && $view_settings['view_id'] == 12345) ) {
// get the slugs from the 'related-tools' field
$related_field_values = get_post_meta( get_the_ID(), 'wpcf-related-tools' );
if(!empty($related_field_values)) {
$target_posts = array();
foreach ($related_field_values as $related_field_value) {
// get the product IDs from each found slug
$post = get_page_by_path($related_field_value, OBJECT, 'product');
if ($post) {
$target_posts[] = $post->ID;
}
}
// set the view's query to only include the related products
$query_args['post__in'] = $target_posts;
}
}
return $query_args;
}
Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors: https://toolset.com/contractors/