I have an archive page. Can I achieve this feature? If a user searches through an archive page and no result returned, then it can automatically insert an entry of that custom type with a default value.
add_shortcode('no_results_auto_post', 'no_results_auto_post_func');
function no_results_auto_post_func() {
$my_post = array(
'post_title' => 'My post',
'post_content' => 'This is my post.',
'post_status' => 'publish',
'post_author' => 1,
);
// Insert the post into the database.
wp_insert_post( $my_post );
}
To execute this custom shortcode, when no results are found in view or WordPress Archive, you can place this custom shortcode inside the [wpv-no-items-found] ... [/wpv-no-items-found] tags, in the "Loop Editor" section.
Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors: https://toolset.com/contractors/
regards,
Waqar
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.