Skip Navigation

[Resolved] CRED – how to update other standard WordPress Fields

This support ticket is created 5 years, 3 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by tony 5 years, 3 months ago.

Assisted by: Waqar.

Author
Posts
#1177600

When generating a CRED form you have the option to create/edit Post Title and Featured Image only. I want to edit the Post Menu order.

Please can you advise how this can be achieved?

Many thanks.
Tony

#1177666

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Tony,

Thank you for contacting us and I'll be happy to assist.

To add or update the post's "Menu Order", through a CRED form, you can use "cred_save_data" hook ( ref: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data ), with the "wp_update_post" function ( ref: https://developer.wordpress.org/reference/functions/wp_update_post/ ).

You'll first add a generic field for the menu order value in the form:


<div class="form-group">
<label>Menu Order</label>
[cred_generic_field type='integer' field='menu-oder']
{
"required":0,
"validate_format":1,
"default":""
}
[/cred_generic_field]
</div>

Next, you can add the following code, in the active theme's "functions.php" file:


add_action('cred_save_data', 'my_menu_order_action',10,2);
function my_menu_order_action($post_id, $form_data)
{
	// if a specific form
	if ($form_data['id']==123)
	{
		if (isset($_POST['menu-oder']))
		{
			$my_post = array(
						'ID'           => $post_id,
						'menu_order'   => $_POST['menu-oder'],
						);

			// Update the post into the database
			wp_update_post( $my_post );
		}
	}
}

Note: Please replace "123" with the actual CRED form's ID, that you'd like to target for this action.

I hope this helps.

regards,
Waqar

#1177735

Hi Waqar

My issue is resolved now. Thank you!

It all worked fine. For future reference I used the above solution on an EDIT form and changed the line:

"default":""
to
"default":"[wpv-post-menu-order]"

Now I can use this field as a secondary sort in a View and allow my users to maintain the menu-order values.

Many thanks
Tony

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