WordPress.org

Ready to get started?Download WordPress

Forums

random excerpt mod help needed (3 posts)

  1. Ovidiu
    Member
    Posted 7 years ago #

    I am using this plugin:

    Plugin Name: Random Excerpt
    Plugin URI: http://www.w-a-s-a-b-i.com/archives/2004/05/27/wordpress-random-posts-plugin/
    Description: Display random excerpt. Usage: random_excerpt();. Made specifically for photoblogs that place thumbnails in the excerpt field.
    Version: 1.0
    Author: Alexander Malov
    Author URI: http://www.w-a-s-a-b-i.com/

    I have posts that contain text and posts with images. I only want random thumbs of those pics posts showing up so I would have to modify the query below from the plugin to only show thumbs from the category pictures or not to show anything from category miscellaneous. can you help me with the sql query please?

    function random_excerpt ($limit = 5, $before = '

  2. ', $after = '
  3. ') {
    global $wpdb, $tableposts;
    $sql = "SELECT ID, post_title, post_excerpt FROM $tableposts WHERE post_status = 'publish' ORDER BY RAND() LIMIT $limit";
    $results = $wpdb->get_results($sql);
    $output = '';
    foreach ($results as $result) {
    $post_title = stripslashes($result->post_title);
    $permalink = get_permalink($result->ID);
    $post_excerpt = ($result->post_excerpt);
    $output .= $before . '' . $post_excerpt . '' . $after;
    }
    echo $output;

  • Ovidiu
    Member
    Posted 7 years ago #

    anyone please?

  • Ovidiu
    Member
    Posted 7 years ago #

    I am playing around with this:

    [code]$sql = "SELECT ID, post_title, post_excerpt FROM $tableposts WHERE post_status = 'publish' AND ID in (SELECT post_id FROM $wpdb->post2cat WHERE category_id != 1;) ORDER BY RAND() LIMIT $limit";[/code]

    but the MYSQL Syntax near the SELECT command is somehow wrong...

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags