Skip Navigation

[Resolved] Front-end Generic Fields not defaulting

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 13 replies, has 2 voices.

Last updated by Minesh 5 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#1198309

The font end edit form fields for Post Status and Post Slug are not defaulting.
However, they do save correctly. Any help is appreciated.

Here's an example edit page:
hidden link

Here's the Edit Partner form:
hidden link

<label>Partner Status</label>
[cred_generic_field field="post_status" type="radio" class="" urlparam=""]
{
"required":0,
"validate_format":0,
"default":["[wpv-post-status]"],
"options":[
{"value":"Draft","label":"Draft"},
{"value":"Publish","label":"Publish"}
]
}
[/cred_generic_field]

<label>Partner Campaign Url</label>
[cred_generic_field field='post_slug' type='textfield' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":"[get_slug]"
}
[/cred_generic_field]

#1198350

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - I've changed the post_status option values as given under and I can see the default radio is selected now:

[cred_generic_field field="post_status" type="radio" class="" urlparam=""]
{
"required":0,
"validate_format":0,
"default":["[wpv-post-status]"],
"options":[
{"value":"draft","label":"Draft"},
{"value":"publish","label":"Publish"}
]
}
[/cred_generic_field]

You can see default radio "Publish" is checked by default:
hidden link

Regarding another field "post_slug" - where did you added the shortcode [get_slug]? what exactly value you want to display with this field?

#1198353

Capitalization? I thought I tried that 🙁 . Cool though, thanks!

I've added the shortcode in the child theme function file

// to update the post slug
add_action('cred_save_data', 'func_change_post_slug', 10, 2);
function func_change_post_slug($post_id, $form_data){
 
    if ($form_data['id']==1647) {
 
        $slug = sanitize_title($_POST['post_slug']);
        wp_update_post(array('ID'=>$post_id,'post_name' => $slug));
    }
  
}
 
// to get the value of post slug
add_shortcode( "get_slug","func_get_slug");
function func_get_slug($post_id, $form_data){
 
    if (isset($_GET['_id']) and $_GET['_id']!='' ) {
        $id = $_GET['_id'];
        $post = get_post($id);
        return $post->post_name;
         
         
    }
  
}
#1198354

Minesh
Supporter

Languages: English (English )

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

Ok - I would like to know here what slug value as default value you want to assign to field "post_slug" - is it partner_id from URL param?

#1198599

Post title as default

#1198601

Minesh
Supporter

Languages: English (English )

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

But which post title? partner_id post title?

So, in the following case - the title of ID 936?
=> hidden link

#1198651

Yea that’s right. Post title for partner

#1198655

Minesh
Supporter

Languages: English (English )

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

Well - I suggest to use slug as you are going to save the slug. So, to get the slug, I changed the shortcode as given under:

add_shortcode( "get_slug","func_get_slug");
function func_get_slug($post_id, $form_data){
  
    if (isset($_GET['partner_id']) and $_GET['partner_id']!='' ) {
        $id = $_GET['partner_id'];
        $post = get_post($id);
        return $post->post_name;
          
          
    }
   
}

Can you please confirm it works for you.

#1198657

Hmmm did you change anything? Front end is showing white screen now

#1198663

Minesh
Supporter

Languages: English (English )

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

Well - dont know whats happend but I've changed the shortcode as given under:

// to get the value of post slug
add_shortcode( "get_slug","func_get_partner_slug");
function func_get_partner_slug(){
   return get_post_field( 'post_name', $_GET['partner_id']); 
      
}

I can see now it works fine - can you please confirm.

#1198823

My issue is resolved now. Thank you!

#1198961

Well, now the Post Status and Post slug do not change anything when saving. I'm taking a deeper look now

#1198971

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?

New threads created by Minesh and linked to this one are listed below:

https://toolset.com/forums/topic/split-front-end-generic-fields-not-defaulting-default-post-status/

#1199067

Minesh
Supporter

Languages: English (English )

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

Well - would you mind to close this ticket. I've split the ticket and we will continue with your new question with a split ticket.