Set up a script to trigger WP’s Search Unleashed Re-index feature (for cron)

Search Unleashed is supposed to automatically add new posts to its index every time someone creates a new post. However, this doesn’t seem to happen for posts under any of our custom post types.

I could manually trigger the re-index from inside the Dashboard using SU’s re-index button. But I’d like to automate it using cron.

Read More

I am now trying to set up a script that I could run through cron. This is what I have so far:

<?php

    // Fire up wordpress
    include $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php';

    /*
     * We're calling this function from the plugin folder, inside the content
     * directory (as opposed to the admin directory) – so when wp-load is called,
     * we're not going to be in the admin section, and we're not going to get access
     * to those functions.  On the bright side, we also don't have to deal with
     * WordPress forcing you to login.  Since we still need those admin functions,
     * include wp-admin/admin-functions.php.  This loads up the admin side and gives
     * us access to the admin functions
    */
    include $_SERVER['DOCUMENT_ROOT'] . '/wp-admin/admin-functions.php';
?>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
    <script type="text/javascript" >
        $.noConflict();
        jQuery(document).ready(function ($) {
        jQuery('#wrapper').Progressor( {
            start:    jQuery('input[name=reindex]'),
            cancel:   'Cancel',
            url:      '<?php echo admin_url('admin-ajax.php') ?>',
            nonce:    '<?php echo wp_create_nonce ('searchunleashed-index')?>',
            finished: 'Finished!'
        });
    });
    </script>
<?php

?>

However, it’s not doing the trick. Is there something I am missing?

Related posts

Leave a Reply