Skip Navigation

[Resolved] Split: Front-end Generic Fields not defaulting – default post status

This support ticket is created 5 years, 11 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 11 replies, has 2 voices.

Last updated by Minesh 5 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#1199066

I removed some code from functions file. It's saving now.
Is it possible to set the default Post Status from current status rather than default to Publish?
And is it possible to check for duplicates on the slug when saving?

#1199069

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - we are using [wpv-post-status] correct? so it will give you the current post status.

To check duplicate on slugs, you can use the form's hook cred_form_validate.
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

#1199446

Well, when I set it to Draft, then load the edit form again, it displays as Published on the edit form rather than Draft.
Here's video hidden link

#1199594

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - can you please share access details as once the ticket is resolved it removes the access details you shared in the previous ticket.

I have set the next reply to private which means only you and I have access to it.

#1199651

No worries, Minesh. Thank you. I'm currently working in that form. I'll check back soon though

#1199654

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Sure - just send me access details when you can.

I have set the next reply to private which means only you and I have access to it.

#1200395

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Post Status (defaults to Publish every time),
=> OK, I've added following shortcode to get post status of partner:

add_shortcode( "get_partner_status","func_get_partner_status");
function func_get_partner_status($atts){
      return get_post_field( 'post_status', $_GET['partner_id']); 
}

Now, the field looks like this - where we used [get_partner_status] to assign default status as well as we used attribute "persist":1, so that the field value will be saved automatically.

[cred_generic_field field="post_status" type="radio" class="" urlparam=""]
{
"persist":1,     
"required":0,
"validate_format":0,
"default":["[get_partner_status]"],
"options":[
{"value":"draft","label":"Draft"},
{"value":"publish","label":"Publish"}
]
}
[/cred_generic_field]

Post Slug (field stays empty every time),
==> I can see the post slug value. For example: hidden link

Post Author (works after 1st save).
=> Do you mean that the current loggin user should be assigned as post author?

#1200609

Thanks you, Minesh. Post status is defaulting correctly now.

For post author, on 1st load of the edit form, it defaults to 'not set', which is fine.
After we assign the author, save changes and reload the form, it still defaults to 'not set' even though the author has actually changed.

Yes, slug is working except for the initial form load. But this isn't a big issue for us since it does default after the first save. I suspect maybe its due to the post being in draft mode, but I'm not sure.

#1200804

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - the wp-admin access details you shared is stop working. Could you please resend me working wp-admin access details.

I have set the next reply to private which means only you and I have access to it.

#1201797

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - Thank you for sharing access details.

I changed the author field as given under:

[cred_generic_field field='post_author' type='select' class='' urlparam='']
{
"persist":1,   
"required":0,
"validate_format":0,
"default":[], 
"options":[[wpv-view name='users-partners']]
}
[/cred_generic_field]

I can see its working now, Can you please confirm.

#1201895

well, it's certainly defaulting to the chosen user, but it's actually saving me (logged in user) as the author.
See video hidden link

#1202138

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - it was not working because the right post field key was not assigned to the following code:

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==1647)
     
{
$my_post = array(
      'ID'           => $post_id,
      'post_author' => $_POST['post_author']
  );
    
// Update the post into the database
  wp_update_post( $my_post );
  
}
}

=> hidden link

I've adjusted the code as above and I can see its working fine. Can you please confirm.