I am using the code below to pull a random post of my site every 6 hour.
if ( false === ( $social_trans_post_id = get_transient( '$social_trans_post_id' ) ) ) {
$args = array('numberposts' => 1, 'orderby' => 'rand');
$social_trans = get_posts($args);
set_transient('$social_trans_post_id', $social_trans[0]->ID, (60*60*6));
} else {
$args = array('post__in' => array($social_trans_post_id));
$social_trans = get_posts($args);
}
To integrate with Twitter, I'd like to only pull posts with 140 characters or less.
I know about <?php echo substr(($post->post_content), 0,140); ?>
which I am using already as a temporary solution.
I tried to setup a condition and this is where I got stuck:
if ( false === ( $social_trans_post_id = get_transient( '$social_trans_post_id' ) ) ) {
$args = array('numberposts' => 1, 'orderby' => 'rand');
$social_trans = get_posts($args);
if (strlen( $social_trans->post_content > 140 ) ) {
// Pull another post?
}
set_transient('$social_trans_post_id', $social_trans[0]->ID, (60*60*6));
} else {
$args = array('post__in' => array($social_trans_post_id));
$social_trans = get_posts($args);
}
)
. If you had debugging enabled you would spot those errors pretty quick.