Saturday, December 16, 2023
HomeMobile MarketingFastBots: Construct A Customized WordPress XML Sitemap For Coaching Your AI Bot

FastBots: Construct A Customized WordPress XML Sitemap For Coaching Your AI Bot


Martech Zone has hundreds of articles, with lots of them outdated. I’ve labored on the location for a number of years to take away or replace a whole bunch of articles, however I nonetheless have many extra. On the identical time, I’d like to coach a pure language bot with my content material, however the very last thing I need to do is practice it on outdated articles.

FastBots is a ChatGPT-powered bot builder that you may initially practice utilizing your sitemap (or different choices). I wanted a filtered sitemap that included all articles modified since a selected date. Moreover, I wished to incorporate my pages and acronyms (a customized put up kind). I didn’t need to embody archive pages for classes and tags or have my dwelling web page because it’s additionally an archive.

Utilizing the code I’m offering on the finish of this text; I constructed a customized WordPress plugin that creates a customized XML sitemap that dynamically refreshes every time I publish a put up. FastBots doesn’t have an automatic retraining methodology as I publish every article, however it is a nice start line for utilizing the platform.

The sitemap imports all of the hyperlinks to coach the AI Bot on:

FastBots: Train a bot from your site's sitemap.

All pages at the moment are imported, and you’ll practice your bot on the relevant information. You even have the chance to take away particular pages. FastBots additionally allowed me to customise my AI bot’s branding and even embody a hyperlink to a related article in my response. There’s additionally a lead request constructed into the platform.

The platform labored flawlessly… you may give my bot a take a look at drive right here:

Launch Martech Zone’s Bot, Marty Construct Your FastBots AI Bot

Customized XML Sitemap

Moderately than add this performance to my theme, I constructed a customized WordPress plugin to construct out a Sitemap. Simply add a listing in your plugins folder, then a PHP file with the next code:

<?php
/*
Plugin Title: Bot Sitemap
Description: Dynamically generates an XML sitemap together with posts modified since a selected date and updates it when a brand new article is added.
Model: 1.0
Writer: Your Title
*/

// Outline the date since when to incorporate modified posts (format: Y-m-d)
$mtz_modified_since_date="2020-01-01";

// Register the operate to replace the sitemap when a put up is revealed
add_action('publish_post', 'mtz_update_sitemap_on_publish');

// Operate to replace the sitemap
operate mtz_update_sitemap_on_publish($post_id) {
    // Examine if the put up just isn't an auto-draft
    if (get_post_status($post_id) != 'auto-draft') {
        mtz_build_dynamic_sitemap();
    }
}

// Foremost operate to construct the sitemap
operate build_bot_sitemap() {
    world $mtz_modified_since_date;

    $args = array(
        'post_type' => 'put up',
        'date_query' => array(
            'column' => 'post_modified',
            'after'  => $mtz_modified_since_date
        ),
        'posts_per_page' => -1 // Retrieve all matching posts
    );

    $postsForSitemap = get_posts($args);

    // Fetch all 'acronym' customized put up kind posts
    $acronymPosts = get_posts(array(
        'post_type' => 'acronym',
        'posts_per_page' => -1,
    ));

    // Fetch all pages besides the house web page
    $pagesForSitemap = get_pages();
    $home_page_id = get_option('page_on_front');

    $sitemap = '<?xml model="1.0" encoding="UTF-8"?>';
    $sitemap .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';

    foreach($postsForSitemap as $put up) {
        setup_postdata($put up);
        if ($post->ID != $home_page_id) {
            $sitemap .= '<url>'.
                          '<loc>'. get_permalink($put up) .'</loc>'.
                          '<lastmod>'. get_the_modified_date('c', $put up) .'</lastmod>'.
                          '<changefreq>weekly</changefreq>'.
                        '</url>';
        }
    }

    foreach($acronymPosts as $put up) {
        setup_postdata($put up);
        if ($post->ID != $home_page_id) {
            $sitemap .= '<url>'.
                          '<loc>'. get_permalink($put up) .'</loc>'.
                          '<lastmod>'. get_the_modified_date('c', $put up) .'</lastmod>'.
                          '<changefreq>weekly</changefreq>'.
                        '</url>';
        }
    }

    foreach($pagesForSitemap as $web page) {
        setup_postdata($web page);
        if ($page->ID != $home_page_id) {
            $sitemap .= '<url>'.
                          '<loc>'. get_permalink($web page) .'</loc>'.
                          '<lastmod>'. get_the_modified_date('c', $web page) .'</lastmod>'.
                          '<changefreq>month-to-month</changefreq>'.
                        '</url>';
        }
    }

    wp_reset_postdata();

    $sitemap .= '</urlset>';

    file_put_contents(get_home_path().'bot-sitemap.xml', $sitemap);
}

// Activate the preliminary sitemap construct on plugin activation
register_activation_hook(__FILE__, 'build_bot_sitemap');

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments