Please can you advise if it is possible to amend the WordPress post attributes field in a Cred form.
[wpv-post-menu-order]
I have tried various formats in expert mode but I keep getting an error message.
There is a problem with post-menu-order field. Please check CRED form.
However a syntax error is being reported when I add the code to my functions.php file:
============
Your PHP code changes were rolled back due to an error on line 16 of file wp-content/themes/toolset-starter-child/functions.php. Please fix and try saving again.
menu_order isn't a supported field in terms of the standard fields you can include in a Toolset Form.
You would need to include a fake menu_order field (a generic field which could have a menu_order slug), and you would then use the cred_save_data hook to take the value of that generic field and use it to update actual menu_order field of the newly published post.
I can display the field in the form now but when I come to update the functions.php file I get a syntax error, which is odd because it must have worked before on an old website that we no longer have.
Line 5
if ($form_data['id']==123)
Any pointers appreciated.
Tony
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 );
}
}
}
Your PHP code changes were rolled back due to an error on line 7 of file wp-content/themes/toolset-starter-child/functions.php. Please fix and try saving again.
syntax error, unexpected identifier " if"
I am using the Toolset Starter Child theme and the Appearance Theme File Editor to edit the functions php file.
Line 7 is
if ($form_data['id']==123)
I have tried the same PHP codes you provided above in a fresh WP installation + the latest version of Toolset plugins, it works fine, I can save it into theme file "functions.php", see my screenshot functions-codes.jpg