How to program and create posts and pages in word press

Preferably. Note: you will edit some key files, so it is recommended to back up the site before you start. If there are no subtopics above, create subtopics or use these subtopics plug-ins. The following is the complete script for automatically publishing posts and the following code description. The functions of the subtheme. You must paste the code into a PHP file.
add_action( ‘admin_init’, ‘QuadLayers_publish_post’ );
Function quadlayers_publish_post(){
if ( get_option( ‘post_is_published_01’ ) != ‘ Yes {)
$posttype = \
$user id = 1;
$categoryID = ‘1’;
$poststatus = \
$leadtitle = \
$leadcontent = \
$leadContent .= ‘ Although it’s expensive, it’s worth it. ‘;
#Build time and date
$timestamp = $minute counter = 0;
$iCounter = 1;
Add $min = 1;
$adjustClockMinutes = 0;
$minuteCounter = $iCounter * $minuteIncrement;
Counter + $minutes = $minutes;
$timeStamp = date(‘Ymd H:i:s’, strtotime(\
#Build article
$new_post = array(
‘post_title’ => $leadTitle,
‘post_content’ => $leadContent,
‘post_status’ => $postStatus,
‘post_date’ => $timeStamp,
‘post_author’ => $userID,
‘post_type’ => $postType,
\
);
#Publishing!
$post_id = wp_insert_post($new_post);
Update_option (\
}
}
Before publishing, you don’t know whether there is a post, so you must register somewhere where you publish the post. Otherwise, posts will be posted every time the back-end screen is loaded.
The option table of the database is the correct place to perform this operation. After posting, use the update_option() function to save the option named post_is_published_01. Then use get_option() to verify that the option exists. If this option exists in the database, the script does nothing. To rerun the script, simply change the option name to post_is_published_02 or as desired. Under the condition of if (), you can see how to define the post content of the first block. You also need to prepare the time and date for WordPress requests.
Finally, the function responsible for postpublishing is wp_insert_post (), which appends all previous data declared in the function. Male page publishing method: Publishing pages in programming mode is a little simpler. In this script, there is no database option to verify that the page has been published. The functions of page and post are different, and the functions of text imprinted post and page are different, so get_page_
You can use the by_title() function to check whether a page with the same name has been previously published. Then insert information about the author, title, name, and other pages.
Publish the page to the WordPress website using the following script: add_action( ‘admin_init’, ‘QuadLayers_publish_page’ );
Function quadlayers_publish_page(){
$check_page_exist = get_page_by_title (\
If (empty) ($check_page_exist){
$page_id = wp_insert_post(
Sort(
\
\
‘post_author’ => 1,
\
\
\
\
“post_type”=>“page”,“post_parent”=>“id_of_the_parent_page_if_it_available”);
}
}Male conclusion to sum up, we have seen several main differences between posts and pages in this guide. Posts are more dynamic, with categories and categories, while pages are more static and unclassified.
In word press, you can easily create pages and posts with a built-in editor, but in some cases, learning how to do this with a little coding can be useful when automating the publishing process to meet specific requirements. In this case, learning how to programmatically create posts and pages may make life easier. This guide explains how to create posts and pages and the differences between scripts. It is recommended to use these scripts by default and customize them according to the site. Have you ever created posts and pages with some code? Does it work as expected? Please let us know in the comments section below! If you like this post, you may be interested in the following topics: Method of redirecting WordPress page WordPress method of converting post type programmatically creating WordPress custom post type guide

Author:

Leave a Reply

Your email address will not be published. Required fields are marked *