• Hi,

    I hope this beautiful plugin is not too dead and someone can help me.

    I am actually displaying a list of top rated posts on a special page, with something like that :

    $arguments = array(
        'post_type'    => 'custom',
        'number'       => 50,                   // max. number of posts to retrieve
        'offset'       => 0,                    // offset from where to start
        'sortby'       => 'bayesian_rating',    // bayesian_rating, rating or votes
        'order'        => 'DESC',               // ASC or DESC
        'date_limit'   => 0,                    // date limit in days
        );
    
        $results = PostRatings()->getTopRated($arguments);
        foreach($results as $post){
    
        ...

    This is working fine. The result of my code makes the request a bit heavy but necessary, and I am using cache to solve that. Anyway, now the problem is I want to filter this “top posts” with a term from a custom taxonomy. I tried theses lines in my arguments :

    'custom-tax' => 'term',

    or

    'tax_query' => array(
        		array(
        			'taxonomy' => 'custom-tax',
        			'field' => 'slug',
        			'terms' => 'term'
        		)
        	)

    Both are not working of course. There is probably other solutions I not find yet, but maybe it is just impossible to do this request with Post Rating plugin ?

    Please help me ??

    https://www.ads-software.com/plugins/post-ratings/

Viewing 1 replies (of 1 total)
  • I am also VERY interested in making this change. I tracked it down to the getTopRated function, but it looks like it would require a complicated change to the SQL.

    Will someone please help us?


    $query = "
    SELECT *, {$bayesian_formula} AS bayesian_rating
    FROM {$wpdb->posts}
    LEFT JOIN(
    SELECT DISTINCT post_id,
    (SELECT CAST(meta_value AS DECIMAL(10)) FROM {$wpdb->postmeta} WHERE {$wpdb->postmeta}.post_id = meta.post_id AND meta_key ='votes') AS votes,
    (SELECT CAST(meta_value AS DECIMAL(10,2)) FROM {$wpdb->postmeta} WHERE {$wpdb->postmeta}.post_id = meta.post_id AND meta_key ='rating') AS rating
    FROM {$wpdb->postmeta} meta )
    AS newmeta ON {$wpdb->posts}.ID = newmeta.post_id
    WHERE post_status = 'publish' AND post_type = '{$post_type}' {$where}
    GROUP BY ID
    ORDER BY {$sortby} {$order}
    LIMIT {$offset}, {$number}
    ";

Viewing 1 replies (of 1 total)
  • The topic ‘Filter Top Ratings by terms’ is closed to new replies.