Evaluating types field of a parent post inside a CRED form

Problem:

shortcode is not designed to understand the “future parent” post ID passed by CRED, but from the users point of view it’s a usability issue or even a bug.

Solution:

We can use a custom shortcde as a workaround for this.

Add to your functions.php of your theme:

function toolset_support_get_field_of_job( $field = 'wpcf-question-one' ) {
  if( ! isset( $_GET['parent_position_id'] ) ) {
    // no parent position id
    return '';
  }

  $question = get_post_meta( $_GET['parent_position_id'], $field, true );

  if( ! $question || empty( $question ) ) {
    // no valid value set in database
    return '';
  }

  // return the question
    return $question;
  }

  function shortcode_toolset_support_get_field_of_job( $atts ) {
    $atts = shortcode_atts( array(
                            'field' => 'wpcf-question-one'
                            ), 
            $atts );

    return toolset_support_get_field_of_job( $atts['field'] );
  }

add_shortcode( 'toolset_support_get_field_of_job', 'shortcode_toolset_support_get_field_of_job' );

 

Note: In your first post you said the link to the form looks like this: https://awesomesite.whatever/position-application/?parent_position_id=150

So I took ‘parent_position_id’ as key. If the real key differs you have to replace it in the above code.

Now go to Toolset -> Settings -> Front-end content and scroll down to the Third-party shortcode arguments section. Add the shortcode toolset_support_get_field_of_job there.

—-

Open you CRED From and you can add your answer/questions like this:

 

This way the fields are only shown if a question is added and the answers are stored correctly.