Skip Navigation

[Resolved] Conditional form

This support ticket is created 6 years, 6 months ago. 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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 6 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#847745

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.

#848470

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

#848863

I found

<?php $posts = get_posts('post_type=grupo&post_child=2');
$count = count($posts);
echo $count;
?>

But It doesn't work.

#849063

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.