WordPress.org

Ready to get started?Download WordPress

Forums

calling a wordpress function in non wordpress folder (1 post)

  1. vurdlak
    Member
    Posted 3 years ago #

    Hello,

    I have a relatively simple problem. In order to minimize the server load, I would like this wordpress function to be executed every x seconds, and not each time each visitor visits my blog:

    function sc_safe_random() {
    	global $wpdb;
    	$query = "SELECT ID FROM $wpdb->posts WHERE post_type = 'post' AND post_password = '' AND post_status = 'publish' ORDER BY RAND() LIMIT 1";
    	$random_id = $wpdb->get_var( $query );
    	return get_permalink($random_id);
    }

    this function returns random post. then I would need to call it in ie. http://www.mysite.com/random/index.php with:

    <a href="<?php echo sc_safe_random() ?>">a random post</a>

    how can I achieve this, since mysite.com/random isn't part of the wordpress? (calling this function), as well as how do I ie. set previous function to be executed each second by server, or only when random/index.php is called wihtout cronjob?

    I do all of this because of my wp caching which can't ignore the random redirect, and when it does, it still uses mass server load. the solution in my head was to call this function ie. each second, then it would return different link in http://www.mysite.com/random/index.php redirect link each time

Topic Closed

This topic has been closed to new replies.

About this Topic