Skip to main content
Tweeted twitter.com/#!/StackWordPress/status/447656575805964288
syntax error
Source Link
Tony Fire
  • 407
  • 1
  • 4
  • 10

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);
            }

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);
            }

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);
            }
Source Link
Tony Fire
  • 407
  • 1
  • 4
  • 10

Query posts by content lenght

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);
            }