Skip Navigation

[Resolved] Selecting layout for a page created with CRED Post Form

This support ticket is created 7 years, 9 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 1 reply, has 2 voices.

Last updated by Beda 7 years, 9 months ago.

Assisted by: Beda.

Author
Posts
#414673
screen.png

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.

#414780

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

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