GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   How-to: Random post order [WP] (https://gfy.com/showthread.php?t=1109727)

madtwin 05-17-2013 01:14 AM

How-to: Random post order [WP]
 
I need to randomize all posts on my WP tube, but like every 1-2 days.

I'm not talking about adding just '&orderby=rand' parameter to the query, it shuffles posts with every page visit/reload and makes some videos appear on page1 and 2...


Anyone?

:helpme

harvey 05-17-2013 01:52 AM

http://codex.wordpress.org/Transients_API

harvey 05-17-2013 01:59 AM

optionally, you can use a seed as an argument and store it as a variable so pagination will get the see and go from there. This is a great way to achieve what you're looking for, but I think it won't work well if you're using cache plugins (well, it will work but the purpose of cache plugins would be defeated)

edit: sorry, now I see you want this to change every couple days, not per session, so just go with Transients API, it's done for this exact purpose

madtwin 05-17-2013 03:27 AM

Thanks, that Transients API does exactly what I need :thumbsup


For those interested in this - How do I create a random post that will last for a day ( not tested )

madtwin 05-17-2013 08:50 AM

Shit... I can't get it work :helpme

I have standard query on index.php like this:

Quote:

<?php if(have_posts()) { ?>

<?php while (have_posts()) : the_post(); ?>

<div class="post" id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_titile(); ?></a>
</div>

<?php endwhile; ?>
So where goes all the Transients API stuff? Something like this?

Quote:

<?php
// Get any existing copy of our transient data
if ( false === ( $special_query_results = get_transient( 'special_query_results' ) ) ) {
// It wasn't there, so regenerate the data and save the transient
$randargs = array('orderby' => 'rand', 'numberposts' => 10);
$special_query_results = get_posts($randargs);
set_transient( 'special_query_results', $special_query_results, 60*60*12 );
}

// Use the data like you would have normally...
$randomposts = get_transient( 'special_query_results' );

global $post;
foreach( $randomposts as $post ) : setup_postdata($post); ?>

<div class="post" id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_titile(); ?></a>
</div>

<?php endforeach; ?>
When using this code I get blank page...

:helpme:helpme:helpme


All times are GMT -7. The time now is 05:27 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc