Hello,
I have CPT 'contrataciones' child of CPT 'Grupo'.
I have a Cred form to create CPT 'contrataciones' and I want to stop displaying it when the number of CPT 'Grupo' that have more than 2 child CPT 'Contrataciones' > 7
Any idea? Thanks.
I can't think of an easy way to accomplish this with Views and CRED. It will require custom code that determines how many Grupos have more than 2 child Contrataciones. You can use conditional HTML to test that value and show or hide the CRED form. If you're comfortable writing PHP, you can use the WordPress Shortcode API to create your shortcode, and I can help you with any Toolset APIs you need to use to query relationships. If you're not comfortable writing PHP, then you may need the assistance of a professional developer. We have a portal where you can connect with independent contractors with Toolset knowledge: https://toolset.com/contractors
I found
<?php $posts = get_posts('post_type=grupo&post_child=2');
$count = count($posts);
echo $count;
?>
But It doesn't work.
I'm not sure what "post_child" is in your example. It doesn't seem to be documented anywhere on the codex:
https://codex.wordpress.org/Class_Reference/WP_Query
https://codex.wordpress.org/Template_Tags/get_posts
https://www.google.com/search?q=site%3Acodex.wordpress.org+%22post_child%22&oq=site%3Acodex.wordpress.org+%22post_child%22&aqs=chrome.0.69i59j69i58.6001j0j7&sourceid=chrome&ie=UTF-8
Anyway, it won't work for post relationships created by Types. A child post is related to a parent post by a single postmeta field, "_wpcf_belongs_slug_id", where the value is the numeric ID of the parent post and "slug" is replaced by the parent post type slug. For example, in your case the Contratacione post has a postmeta entry "_wpcf_belongs_grupo_id" with the parent Grupo post's ID as the value.