Skip Navigation

[Resuelto] Stop using layouts for pages after wp_insert_post

This support ticket is created hace 6 años, 11 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

Este tema contiene 4 respuestas, tiene 2 mensajes.

Última actualización por Mario hace 6 años, 11 meses.

Asistido por: Minesh.

Autor
Mensajes
#603160
2018-01-03_20h16_28.png

I am trying to: Insert a new post via php.

$post_id=wp_insert_post(
         array(
            'post_content'   => "new page.",
            'post_name'      => "post name",
            'post_title'     => "message",
            'post_status'    => 'publish',
            'post_type'      => 'page'
            'page_template' =>  $new_page_template 
         )
      );

Since i use toolset-layouts with template layout for pages per default ("layout for pages"), i always get assigned this layout to my newly created page. I have to go to the interface manually and click "stop using this template layout for pages".

How could i prevent, toolset automatically assigning this template layout to this created page? I want to have a blank, native created page.
Thanks in advance for any hints.

#603513

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - _layouts_template is the post meta key that holds the Layouts template name as meta value.

So - you need to use hook wp_insert_post_data and set correct action from there:
=> https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data

For example:

function func_remove_layouts_template_connection( $post_id, $post, $update ) {
       if($post->post_type=='page'){
              	delete_post_meta( $post_id,'_layouts_template');
        }
}
add_action( 'wp_insert_post', 'func_remove_layouts_template_connection', 10, 3 );

You should adjust the above code as required.

#603535
2018-01-04_19h58_16.png

Thank you so much Minesh.
Works fine but unfortunatelly it looks like the "Content Template" is used since the Template Layout field is empty.
If i set Content Template to "None" manually it works. But how could i finally do this with a filter or post_meta_field?
I tried

delete_post_meta( $post_id, '_wp_page_template' );

, but doesn´t work.

#603706

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Well - view's template stored with postmeta key _views_template .

Could you please try to use following code and try to resolve your issue.

delete_post_meta( $post_id, '_views_template' );
#603734

Wonderfull and perfect. Thank you Minesh. Thats it.