Answer the question
In order to leave comments, you need to log in
How to write template, image, tile, description data to database in wordpress?
Hello.
$updated_post_arr_ = array(
'post_title' => 'Test20201',
'post_content' => $contents[0]["name_bank_ru"],
'post_author' => '5',
'comment_status' => 'open',
'page_template' => 'content-current.php', //записывает поумолчанию default
'post_status' => 'publish',
'post_category' => array(129),
'tags_input' => array('Активен')
);
// обновляем пост (все остальные его параметры останутся прежними)
$my_post_id_ = wp_insert_post($updated_post_arr_);
Answer the question
In order to leave comments, you need to log in
The page_template table field has been removed, now the template for the permanent page is set in the _wp_page_template metafield using add_post_meta()
either update_post_meta()
Titles and descriptions by default in WP, I will assume that you are using some kind of SEO plugin and, most likely, it also stores this data in post meta fields. Therefore, find in the documentation or the database what the keys for these fields are called and use the same functions add_post_meta()
or update_post_meta()
As for setting the image of the record, you can use the function media_sideload_image()
or a combination of wp_insert_attachment()
and set_post_thumbnail()
. The difference is that the former uploads the image to the WP media library and sets it up for the post, while the latter only creates posts in the
PS database. To separately set categories, taxonomies and tags, you may need the functionwp_set_object_terms()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question