@deron
To add a new Elementor post programmatically, you can use the following steps:
- Include the necessary files and functions:
1
2
3
|
require_once ABSPATH . 'wp-admin/includes/post.php';
require_once ABSPATH . 'wp-admin/includes/taxonomy.php';
require_once ABSPATH . 'wp-admin/includes/media.php';
|
- Create a new post using wp_insert_post() function:
1
2
3
4
5
6
7
8
|
$new_post = array(
'post_title' => 'New Elementor Post',
'post_content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
'post_status' => 'publish',
'post_type' => 'post'
);
$post_id = wp_insert_post($new_post);
|
- Assign the Elementor template to the post using update_post_meta():
1
2
|
update_post_meta($post_id, '_elementor_template_type', 'single');
update_post_meta($post_id, '_elementor_edit_mode', 'builder');
|
- Set the Elementor template ID for the post using update_post_meta():
1
2
|
$elementor_template_id = 123; // Replace with the ID of the Elementor template you want to use
update_post_meta($post_id, '_elementor_template_id', $elementor_template_id);
|
- Reload rewrite rules to update the post URL:
By following these steps, you can programmatically add a new Elementor post in WordPress. Just make sure to replace the placeholder values with your actual data.