I would prefer to do it all server-side if possible. I have no budget for a contractor unfortunately.
Here's what I have done so far:
I created a custom shortcode that counts the number of child posts as such:
add_shortcode('address-count', 'address_count_func');
function address_count_func($atts) {
global $post;
$child_posts = toolset_get_related_posts($post->ID,'service-request-service-address','parent',999,0,array(),'post_id','child');
return count($child_posts);
}
It does output the correct child post count and I have registered the shortcode to be used in conditionals(see attached image).
If you look here: hidden link
You can see that it correctly outputs 2.
However, I have added a conditional that should only be true if [address-count] is greater than or equal to 1:
[wpv-conditional if="( '[address-count]' gte '1' )"]
But the conditional doesn't seem to work as expected. I have tried not equal to zero as well with the same result, and even tried setting it to be true if equal to the exact known count of child posts, but it doesn't fire.
Question 1 is why isn't the conditional working with my custom shortcode?
This is of course leading back to solving the original question, which I intend to solve by counting child posts which have a particular field value set by cred_save_data as shown below:
I have already created the code to add the value to the field
if ($form_data['id']==372)//----------------------------------------------------------------------Service address - Set status of services selected
{
update_post_meta($post_id, 'wpcf-address-status', 'services selected');
}
Question 2 is once the conditional is working with my address-count shortcode, how would I count ONLY child posts with that custom field value using PHP?
Hopefully this is clear.
I appreciate your help Minesh.