Support » Plugins » Hacks » calling a wordpress function in non wordpress folder

  • 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. with:

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

    how can I achieve this, since 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 redirect link each time

  • The topic ‘calling a wordpress function in non wordpress folder’ is closed to new replies.