Skip Navigation

[Resolved] Hide fields if CRED form is shown

This support ticket is created 7 years 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 8 replies, has 2 voices.

Last updated by Beda 7 years ago.

Assisted by: Beda.

Author
Posts
#511031

Hi,

I created a layout to show a CPT and the children posts (used as a repeater as per your guidelines). More specifically, I am using visual editors and a few cells to show the parent CPT, and a view to show a grid with all the children posts.

A button triggers the "Edit Form" for the parent CPT. Now I have two questions:

  • Is there a way in Toolset to hide the fields while the edit form is visible? I'd like the page to show either the content of the post or the edit form.
  • What is the best approach to edit also children posts from the front-end? Can I add another Edit link? Can I edit them all together, or does it have to be an edit link per child post?

Thanks

#511160

With Layouts it's a bit tricky to load only the CRED Edit Form.

One thing is to use a Custom Code, that calls a specific layout only when you use a specific Edit Form.

This code is visible below:

add_filter('get_layout_id_for_render', function($id){

                //declare the WordPress gobal $post
                //https://codex.wordpress.org/Function_Reference/$post		
		global $post; 
 
                //If the current Post is existent (not null) and the post type is "code-snippet", and we have a URL "GET" parameter for the "cred-edit-form"
                // You just need to change your post Type slug
		if( null !== $post && $post->post_type === 'code-snippet' && isset($_GET['cred-edit-form']) ){
                        //Here we return the Layouts ID where the CRED Edit Form Cell is inserted to
                        //You need to create this Layout, insert the CRED Edit Cell, and copy paste the ID of that Layout here beow. Do NOT assign that Layout to any content.
			$id = '4384';
		}

                //Here we return the finshed product. This now tells Layouts to load a specific Layout when all above conditions are true.
		return $id;
} );

See the inline comments that will help you to achieve the same on your page.

This should help you to achieve the first goal.

Now for Child Edit Links, you should display those with a View, that queries Child posts.
If so, then you can simply add the Link to edit them as used to, and apply a similar code as above, to load another Layout, in case you want the same behaviour as in #1

I hope everything has been explained to you in a suitable way, if not, please don't hesitate to challenge me 🙂

#511384

Hi Beda,

thanks, I am testing the answers right now.

I implemented the filter in my functions.php and it works. Except, if the layout is a child layout (i.e. the parent is covering for header and footer), only the child is shown. Is that correct? Or could I have done something wrong?

Thanks
Mirko

#511387

You should assign the Parent Layout to the Layout you call in that Code.

Just as with other "Child Layouts".

Have you done that?

It's done in Toolset > Layouts > your_layout(with the cred form) > Edit > Set parent.

#511961
01.png

Hi Beda,

Please see the attached picture. The layout is set as a child of the main layout with header and footer (already working fine with other layouts).

And this is the code in my functions.php:

add_filter('get_layout_id_for_render', 'pthq_edit_project');
function pthq_edit_project($id)
{
    global $post;
    if (null !== $post && $post->post_type === 'projects' && isset($_GET['cred-edit-form'])) {
        $id = '46945';
    }
    return $id;
}

What could I have missed?

#511970

This works just fine on my install, I gonna outline here the steps.

1. Use Toolset Starter Theme
2. Create 3 Layouts:
- a Layout for the Posts (display them). This also holds a Post Content Cell so the CRED Edit link can be inserted in a Post Content and displayed (that's just one method to do that of course)
- a Layout for the CRED Cell only
- a Parent Layout. This must be set as parent of both above Layouts.
3. Insert the Code to your functions.php and call the Layout with the CRED Cell.

Now, when I visit a post, I see my Posts Layout, and it's parent.
Then I click on the Link for editing the Post with CRED and that leads to the CRED Layout + it's parent correctly.

If this does not work on your end, please provide access to a Test Site where I can see what's wrong.

Here is the code I use again:

add_filter('get_layout_id_for_render', function($id){
 
                //declare the WordPress gobal $post
                //https://codex.wordpress.org/Function_Reference/$post      
        global $post; 
  
                //If the current Post is existent (not null) and the post type is "code-snippet", and we have a URL "GET" parameter for the "cred-edit-form"
                // You just need to change your post Type slug
        if( null !== $post && $post->post_type === 'code-snippet' && isset($_GET['cred-edit-form']) ){
                        //Here we return the Layouts ID where the CRED Edit Form Cell is inserted to
                        //You need to create this Layout, insert the CRED Edit Cell, and copy paste the ID of that Layout here beow. Do NOT assign that Layout to any content.
            $id = '33';
        }
 
                //Here we return the finshed product. This now tells Layouts to load a specific Layout when all above conditions are true.
        return $id;
} );
#513865
Screen Shot 2017-04-16 at 22.12.01.png

Hi Beda,

Just to confirm:
1. I created a layout to display the CPT "projects" - and it is a child-layout. In that layout, I used a "visual editor" cell to add the Edit link (I am not sure how to use the Post Content Cell for that).
2. I created another layout (also a child-layout of the same parent layout), with a cell with a title and another cell with the CRED form (see image) - id is 46945.
3. I added the function in my functions.php using the ID mentioned in point 2...

When I click on Edit I see the edit form but
a) yet without header and footer (i.e. without parent layout)
b) without even the title cell
c) the form is higher than the screen but there is no scroll bar...

the second point, in particular, makes me think the layout is not being loaded correctly. Is there anything else I can check?

Thanks

#513939

This is not happening on a clean WordPress install with Toolset only.

Can you grant me edit access to your site, where I can check the code and eventaully change it?

This will include eventual crucial changes to the site so it's better to provide access to a staging site if possible.

#513954

When I call the "front end layouts editor", the parent is there!

Only when I view it, it's not there.

This must be due to a Theme issue, a Plugin (cache as example) or others.

Please disable all Plugins, but Toolset, and use our Toolset Starter Theme.

If that works, it is a bug with one of the several Plugins or the theme. I suspect the cache.

The code and setup is correct so far, therefore it must be a compatibility conflict.

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