WordPress.org

Ready to get started?Download WordPress

Forums

WP Favorite Posts
showing all favorited posts on a page. help with query? (2 posts)

  1. vincej
    Member
    Posted 2 years ago #

    trying to show all posts being watched by more than 1 visitor on a page for my own admin purposes.

    I've got this so far, but can't see
    global $wpdb;
    $wpdb->query(
    "
    SELECT * FROM $wpdb->postmeta
    WHERE 'meta_key' LIKE 'wpfp_favorites'
    AND 'meta_value' > 1
    "
    );
    query_posts($wpdb);

    then typically in a page template I do this, to use a template that shows specific information about the posts gathered.

    include (TEMPLATEPATH.'/layout/imagesoption_wide.php');

    This template includes the typical
    while (have_posts()) : the_post();

    so what am I doing wrong in the sql query above?

    The final result will be a page which gives me a visual on the posts being favorited AND a list of page ID numbers (in my case, e-commerce site, so SKU's) which I can place on Special each week to generate more sales.

    any help appreciated

    http://wordpress.org/extend/plugins/wp-favorite-posts/

  2. vincej
    Member
    Posted 2 years ago #

    oops. ignore.
    found the solution in between the code for the plugin itself.
    Stole this from the widget php file, I think.

    global $wpdb;
    $limit = 1000;
        $query = "SELECT post_id, meta_value, post_status FROM $wpdb->postmeta";
       $query .= " LEFT JOIN $wpdb->posts ON post_id=$wpdb->posts.ID";
     $query .= " WHERE post_status='publish' AND meta_key='wpfp_favorites' AND meta_value > 0 ORDER BY ROUND(meta_value) DESC LIMIT 0, $limit"; 
    
        $results = $wpdb->get_results($query);
        if ($results) {
            echo "<ul>";
            foreach ($results as $o):
                $p = get_post($o->post_id);
                echo "<li>";
                echo "<a href='".get_permalink($o->post_id)."' title='". $p->post_title ."'>" . $p->post_title . "</a> ($o->meta_value)";
                echo "</li>";
            endforeach;
            echo "</ul>";
       }

    then I se a second run through to get specific info I will need for the ecommerce section updates.

    echo ('POST ID ' . $o->post_id .' SKU ' . get_post_meta($o->post_id , 'sku', true) ) ;

    a nice simple clean page report for currently favorited (watched) items. Just like the big boys like ebay :-)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic