Skip Navigation

[Closed] Public/Private post drop down

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

Last updated by Minesh 1 year, 9 months ago.

Assisted by: Minesh.

Author
Posts
#2629777

I'm trying to create an ajax based form to saved the post status on custom posts created by users.

I'm using an edit form:

[credform]
	<select id="chart_visibility" name="chart_visibility">
    <option value="public">Public</option>
    <option value="private">Private</option>
</select>
	[cred_field field='form_submit' output='bootstrap' value='Save' class='btn btn-primary btn-lg']
[/credform]
add_action('cred_save_data', 'set_chart_visibility',10,2);
function set_chart_visibility($post_id, $form_data) {

    // Check that this is the correct form.
    if ($form_data['id'] != 161917) {
        return;
    }

    // Get the value of the dropdown.
    $visibility = $_POST['chart_visibility'];

    // Set the post status.
    if ($visibility == 'public') {
        $post_status = 'publish';
    } else {
        $post_status = 'private';
    }

    // Update the post.
    wp_update_post(array(
        'ID' => $post_id,
        'post_status' => $post_status,
    ));
}

This works well however, I need help setting the option value as the actual option rather than the default value? Any ideas how?

Best regards and thanks in advance,
Kyle

#2629951

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Kyle

I've read through your code and I see what you are trying to do.

But I'm not sure what you need help with, I don't follow what you mean by "setting the option value as the actual option rather than the default value".

Could you elaborate on the problem?

#2630143

Hi Nigel,

Thank you for your response.

I'm trying to create a drop down for the user to decide whether the post is public or private. I'm trying to figure out how to set the current status when loading the page.

For example, if the post is set to publish the drop down will load as published etc.

#2630235

Minesh
Supporter

Languages: English (English )

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

Do you have post edit form or post form to create new entry?

Can you please share problem URL where you added your form as well as admin access details?

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

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

The topic ‘[Closed] Public/Private post drop down’ is closed to new replies.