Skip Navigation

[Resolved] Setting up parent post in front end

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user wanted to set the parent post automatically when creating a chid post. Now the user will CREATE that parent post and when creating the child that parent should be set automatically.

Solution:

Add the following to your functions.php file

// Add Shortcode
function user_post_id( $atts ) {
 
    // Attributes
    $atts = shortcode_atts(
        array(
            'author_id' => '',
            'cpt' => '',
        ),
        $atts
    );
    $args = array(
        'author'        =>  $atts['author_id'],
        'orderby'       =>  'post_date',
        'order'         =>  'ASC',
        'posts_per_page' => 1,
        'post_type'=> $atts['cpt']
        );
    $post=get_posts($args); 
    return $post[0]->ID;
 
}
add_shortcode( 'user_post_id', 'user_post_id' );

Then on your CRED form where it has the Parent Field on the edit form page add this as the value [user_post_id author_id="[wpv-current-user info='id']" cpt='post']

This support ticket is created 5 years, 12 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 20 replies, has 2 voices.

Last updated by geoffD 5 years, 11 months ago.

Assisted by: Shane.

Author
Posts
#844315

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Geoff,

Would you mind providing me with access so that I can assist better?

The private fields will be enabled for your next response.

Also let me know the page that you are currently testing this on.

Thanks,
Shane

#845048

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Geoff,

I've fixed the issue and it should now be working .

Please try and let me know.

Thanks,
Shane

#845845

That's fantastic Shane...It works!

Could you please let me know what you did to get it working for future reference.

Many thanks

Geoff

#847548

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Geoff,

The issue was with the format of the short code when you passed it as a parameter and you needed to have changed the CPT it was looking for.

		[cred_field field='_wpcf_belongs_user-will_id' value="[user_post_id author_id='[wpv-current-user info='id']' cpt='user-will']" class='form-control' output='bootstrap']

Please let me know if this helps.

Thanks,
Shane

#877527

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Geoff,

Could you mark this ticket as resolved if there are no further questions on this.

Thanks,
Shane

#879008

Thanks for your help Shane...I have a couple of other issues but will open a separate ticket for that..

Best wishes

Geoff

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.