I am trying to create pages with CRED Post Form.
I need one of these two possibilities for my editors:
1) assign the content not only to a page, but to a page with a special layout, which has been designed before with Layouts
or
2) Offer the editor a field (select or radio) to chose one predefined layout (designed before with Layouts).
Any idea how to solve this?
Thank you!
O.
If you create Pages with CRED, how would you assign this new page to another page?
This does not work, in WordPress.
Unless perhaps you would use Parent Pages, but that will not allow you to inherit the Parent pages layout.
Also, there is no Toolset feature to add a Field to choose the layout.
Either (natively) you assign your Layout to ALL pages, which will make appear all pages with the same layout on creation, or, you use Custom Code.
You can use a CRED save data action.
https://toolset.com/documentation/user-guides/cred-api/#csd
In that action, you tell CRED to do the following:
1. You get the Types Field value from the Post/page submitted
(this is the Types field that your user chooses, which will determine what Layout to assign to the Page
2. According to this value (with an if statement) you assign the layout to the page with a Custom Code similar to the below:
function my_save_data_action($post_id, $form_data){
//this is the preferred Layout ID. YOu can create many such variables
$preferred_layout = 5745;
//Get our Field value from the post
//https://developer.wordpress.org/reference/functions/get_post_meta/
$field_value = get_post_meta( int $post_id, string $key = '', bool $single = false );
if( $field_value === 'your_value'){
//Update the Post Field "_layouts_template" which holds the ID of the Layout you want in the post itself (or page)
//https://codex.wordpress.org/Function_Reference/update_post_meta
update_post_meta($post_id, $meta_key, $meta_value, $prev_value);
}
}
add_action('cred_save_data', 'my_save_data_action',10,2);
Above Code holds essential Comments that illustrate how to use this and give guidance also to the required DOC of WordPress