Hi Julie,
Thank you for contacting us and I'll be happy to assist.
For a better performance and consistency, custom shortcodes can be used when a complex comparison is involved.
For example, you can add the following code, at the bottom of your active child theme’s “functions.php” file:
// custom shortcode to check if user image is set
add_shortcode('check_count_condition', 'check_A_B_condition_func');
function check_A_B_condition_func() {
$slug_post_type_a = "post_a";
$slug_post_type_b = "post_b";
$custom_field_days_a = "wpcf-total-days";
// get total number of days from all post types A
$args_a = array(
'posts_per_page' => -1,
'post_type' => $slug_post_type_a,
'post_status' => 'publish',
);
$posts_a_array = get_posts( $args_a );
$posts_a_days_count = 0;
foreach ( $posts_a_array as $post_a ) {
$posts_a_days_count = $posts_a_days_count + get_post_meta( $post_a -> ID, $custom_field_days_a, true );
}
// get total number of post types B
$args_b = array(
'posts_per_page' => -1,
'post_type' => $slug_post_type_b,
'post_status' => 'publish',
);
$posts_b_array = get_posts( $args_b );
$posts_b_count = count($posts_b_array);
// return "1" if total number of days from all post types A is greater than total number of post type B or else "0"
if ($posts_a_days_count > $posts_b_count)
{
return 1;
}
else
{
return 0;
}
}
Note: please remember to update the values of “$slug_post_type_a”, “$slug_post_type_b” and “$custom_field_days_a”, as they’re being used on your website.
Next, register this new shortcode [check_count_condition] with Toolset, so it can be used inside its built-in shortcodes, as explained in the following guide:
https://toolset.com/documentation/user-guides/shortcodes-within-shortcodes/
After that, you’ll be able to wrap your conditional content, using the following conditions and without the extra views:
[wpv-conditional if="( [check_count_condition] eq '1' )"]
Some content when condition is true
[/wpv-conditional]
[wpv-conditional if="( [check_count_condition] eq '0' )"]
Some content when condition is false
[/wpv-conditional]
I hope this helps! Please let us know if you need any further assistance.
regards,
Waqar