Support » Fixing WordPress » How to short the length text in this code?

  • Hi, i have another issue.
    I try to show a random post, not only the link but with some text from article. I made the code, i recive the title, the post text, but it is all the article, and now i whant to use just some words of it…
    The code is:

    function single_random_post_text() {
    		    global $wpdb;
    		    $query = "SELECT id, post_content, post_title, post_name FROM $wpdb->posts WHERE ((post_status='publish') AND (post_type = 'post') AND ($wpdb->posts.post_password = '')) ORDER BY RAND() LIMIT 1";
    		    $randompost = $wpdb->get_results($query);
    		    $post = $randompost[0];
    		    $post_content = "<p>$post->post_content</p>\n";
    		    $post_title = htmlspecialchars(stripslashes($post->post_title));
    		    $title_post .= "<h2><a href=\"" . get_permalink($post->id) . "\" title=\"". $post_title ."\">" . $post_title ."</a></h2>\n";
    		    echo $title_post;
    		    echo $post_content;
    
    }

    Pls help me with that!

Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to short the length text in this code?’ is closed to new replies.