S
S
SanSoonShin2018-03-29 14:16:23
WordPress
SanSoonShin, 2018-03-29 14:16:23

How to programmatically create a page in wordpress in a plugin?

How to programmatically create a page in wordpress in a plugin? Actually, this is not MVC, and even normal routing is not there. Now I'm not talking about the page in the admin panel, but on the site itself. I am working with WordPress for the first time, and I have not dealt with such ancient systems, but something needs to be done. Can anyone please describe how to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
E, 2018-03-29
@aylo

// Создаем массив данных новой записи
$post_data = array(
  'post_title'    => wp_strip_all_tags( 'title' ),
  'post_content'  =>'post_content',
'post_name' => 'slug',
  'post_status'   => 'publish',
  'post_author'   => 1,
);

// Вставляем запись в базу данных
$post_id = wp_insert_post( $post_data );

I recommend specifying 'post_type' => 'you_post_type_name' in the arguments, so as not to mix anything anywhere, and the search will then be much easier.
from

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question