Hello support team,
i am trying to display a repeatable field in php with a single types render field.
This works fine, but i want it to show the whole content only if one of the fields is filled.
Here my example:
<?php if(!empty(types_render_field('video-link-proj'))){?>
<div class="container">
<span class="line-through">
</span>
<h2 class="text-center">Videos</h2>
</div>
<div class="container" id="videos">
<?php // Main Features
$args = array(
'post_type' => 'videos-proj',
'numberposts' => -1,
'toolset_relationships' => array(
'role' => 'child',
'related_to' => get_the_ID(),
'relationship' => 'videos-proj',
),
'meta_key' => 'toolset-post-sortorder',
'orderby' => 'meta_value_num',
'order' => 'ASC',
);
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ){
$the_query->the_post(); ?>
<div class="six columns">
<iframe width="100%" height="290" src="hidden link;?php echo types_render_field('video-link-proj') ;?>" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<?php
}
?>
<?php wp_reset_query();?>
</div>
<!--Video-Con-->
<?php }?>
In this case i try to show the headlines (outside the loop) only if the renderfield is filled.
This is not working. A screenshot of my backend is attached to this.
The site:
hidden link
Hello,
The Toolset Repeatable Field Groups are based on one-to-many relationship, you can not check the child post fields in parent post.
In your case, you just need to add a custom field filter in the query, for example:
<?php // Main Features
$args = array(
'post_type' => 'videos-proj',
'numberposts' => -1,
'toolset_relationships' => array(
'role' => 'child',
'related_to' => get_the_ID(),
'relationship' => 'videos-proj',
),
'meta_key' => 'toolset-post-sortorder',
'orderby' => 'meta_value_num',
'order' => 'ASC',
// Add below field filters
'meta_query' => array(
array(
'key' => 'wpcf-video-link-proj',
'value' => '',
'compare' => '!=',
),
),
);
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ){
$the_query->the_post(); ?>
<div class="container">
Here display the whole content
</div>
<?php
}
?>
<?php wp_reset_query();?>
More help:
https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters
thank you for the support!