Wednesday, December 20, 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 lots of 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 prepare it on outdated articles.

FastBots is a ChatGPT-powered bot builder you could initially prepare utilizing your sitemap (or different choices). I wanted a filtered sitemap that included all articles modified since a particular date. Moreover, I wished to incorporate my pages and acronyms (a customized publish kind). I didn’t need to embody archive pages for classes and tags or have my house 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 publish. FastBots doesn’t have an automatic retraining technique as I publish every article, however this can be 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 are actually imported, and you may prepare your bot on the relevant knowledge. 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 can provide my bot a check drive right here:

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

Customized XML Sitemap

Slightly 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 Identify: Bot Sitemap
Description: Dynamically generates an XML sitemap together with posts modified since a particular date and updates it when a brand new article is added.
Model: 1.0
Creator: Your Identify
*/

// 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 publish is printed
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 publish is just not an auto-draft
    if (get_post_status($post_id) != 'auto-draft') {
        mtz_build_dynamic_sitemap();
    }
}

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

    $args = array(
        'post_type' => 'publish',
        '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 publish 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 $publish) {
        setup_postdata($publish);
        if ($post->ID != $home_page_id) {
            $sitemap .= '<url>'.
                          '<loc>'. get_permalink($publish) .'</loc>'.
                          '<lastmod>'. get_the_modified_date('c', $publish) .'</lastmod>'.
                          '<changefreq>weekly</changefreq>'.
                        '</url>';
        }
    }

    foreach($acronymPosts as $publish) {
        setup_postdata($publish);
        if ($post->ID != $home_page_id) {
            $sitemap .= '<url>'.
                          '<loc>'. get_permalink($publish) .'</loc>'.
                          '<lastmod>'. get_the_modified_date('c', $publish) .'</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