Support » Plugins » Hacks » Random post according to localization

  • Resolved DragoWeb

    (@dragoeco)


    Hi all. I’m searching for a way to get a ling to redirect to a radom post according the language selected by the visitor. I’ve created my own button but I just need a link who can do that. Maybe someting like:
    mysite.com/?display-post&orderby=rand
    or maybe a modification to function.php file like here
    I have 2 languages and about 10 categories on each languages.
    If anyone have an idea, he’ll makes my day 🙂 Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter DragoWeb

    (@dragoeco)

    Ok, I discovered that I have a randompost.php file with my template. Here is the code:

    <?php
    /* Template Name: Random Post */
    $randomPost = get_posts(array(
    'numberposts' => 1,
    'orderby' => 'rand'
    ));
    foreach ($randomPost as $post) {
    wp_redirect(get_permalink($post->ID));
    exit();
    }

    So, can I add something like ‘lang => current’ in there?

    Thread Starter DragoWeb

    (@dragoeco)

    Ok, Ive found the solution:
    I just added this line:
    'suppress_filters' => false,
    So, here is the full code:

    $randomPost = get_posts(array(
    'numberposts' => 1,
    'suppress_filters' => false,
    'orderby' => 'rand'
    ));

    Solution comes from here: http://codex.wordpress.org/Template_Tags/get_posts

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Random post according to localization’ is closed to new replies.