Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author grosbouff

    (@grosbouff)

    This is technically possible, but I haven’t had the time to implement it yet.

    Thread Starter Prabin

    (@prabin04)

    it’d be great if you implement this feature in this plugin.
    like using short-code or something like that to show topics with most votes in top. ??
    I think we need to fetch value from db to that right ?

    Plugin Author grosbouff

    (@grosbouff)

    Hi @lionel,

    I just updated the plugin to version 1.0.6 and I did implement a query filter to allow to sort posts by score or vote count.
    See this commit on github : Allow to filter query to sort items by score or votes count.

    Donations are welcome !

    grosbouff

    Thanks grosbouff for the update!

    Im new to it. Can you tell me where or how exactly I have to implement the sort querie in my wp? Do I have to extend the shortcode of bbpress in my page?
    I would like to sort it by ‘count_desc’.

    Best regards,
    Theo

    Plugin Author grosbouff

    (@grosbouff)

    You’ve got to create a custom query (or to filter an existing one) and set the value score_desc for the argument vote_sort.
    Example (not tested) :

    <?php
    $best_rated_topics_args = array(
      'post_type'       => bbp_topic_post_type(), //or 'topic'
      'posts_per_page'  => 5,
      'vote_sort'       => 'score_desc' //plugin
    );
    
    $best_rated_topics = new WP_Query( $best_rated_topics_args );
    ?>

    The code doesn’t work as expected. I’m getting posts instead of topics in returned. I created a new REST endpoint using the following code and received the unexpected results as below:

    add_action( 'rest_api_init', function () {
        register_rest_route( 'bbpress_ext/v1', '/test1', array(
            'methods' => 'GET',
            'callback' => 'ldp_test1',
        ) );
    } );
    
    function ldp_test1( $request ) {
    	$best_rated_topics_args = array(
    	  'post_type'       => bbp_topic_post_type(), //or 'topic'
    	  'posts_per_page'  => 5,
    	  'vote_sort'       => 'score_desc' //plugin
    	);
    
    	$best_rated_topics = new WP_Query( $best_rated_topics_args );
    
    	return $best_rated_topics;
    }

    Executing the endpoint yielded "post_type": "post" instead of "post_type": "topic"

    {
      "query": {
        "post_type": null,
        "posts_per_page": 5,
        "vote_sort": "score_desc"
      },
      "query_vars": {
        "post_type": "",
        "posts_per_page": 5,
        "vote_sort": "score_desc",
        "error": "",
        "m": "",
        "p": 0,
        "post_parent": "",
        "subpost": "",
        "subpost_id": "",
        "attachment": "",
        "attachment_id": 0,
        "name": "",
        "static": "",
        "pagename": "",
        "page_id": 0,
        "second": "",
        "minute": "",
        "hour": "",
        "day": 0,
        "monthnum": 0,
        "year": 0,
        "w": 0,
        "category_name": "",
        "tag": "",
        "cat": "",
        "tag_id": "",
        "author": "",
        "author_name": "",
        "feed": "",
        "tb": "",
        "paged": 0,
        "comments_popup": "",
        "meta_key": "",
        "meta_value": "",
        "preview": "",
        "s": "",
        "sentence": "",
        "fields": "",
        "menu_order": "",
        "category__in": [],
        "category__not_in": [],
        "category__and": [],
        "post__in": [],
        "post__not_in": [],
        "tag__in": [],
        "tag__not_in": [],
        "tag__and": [],
        "tag_slug__in": [],
        "tag_slug__and": [],
        "post_parent__in": [],
        "post_parent__not_in": [],
        "author__in": [],
        "author__not_in": [],
        "ignore_sticky_posts": false,
        "suppress_filters": false,
        "cache_results": true,
        "update_post_term_cache": true,
        "update_post_meta_cache": true,
        "nopaging": false,
        "comments_per_page": "50",
        "no_found_rows": false,
        "order": "DESC"
      },
      "tax_query": {
        "queries": [],
        "relation": "AND",
        "queried_terms": [],
        "primary_table": "wp_posts",
        "primary_id_column": "ID"
      },
      "meta_query": {
        "queries": [],
        "relation": null,
        "meta_table": null,
        "meta_id_column": null,
        "primary_table": null,
        "primary_id_column": null
      },
      "date_query": false,
      "request": "SELECT SQL_CALC_FOUND_ROWS  wp_posts.ID FROM wp_posts  WHERE 1=1  AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'closed')  ORDER BY wp_posts.post_date DESC LIMIT 0, 5",
      "posts": [
        {
          "ID": 37,
          "post_author": "1",
          "post_date": "2008-09-11 22:20:17",
          "post_date_gmt": "2008-09-12 03:20:17",
          "post_content": "Nulla sagittis convallis arcu. Sed sed nunc. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo. Fusce in est. Sed nec diam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Quisque semper nibh eget nibh. Sed tempor. Fusce erat.\n\n<h3>An Ordered List</h3>\n\n<ol>\n<li>Vestibulum in mauris semper tortor interdum ultrices.</li>\n<li>Sed vel lorem et justo laoreet bibendum. Donec dictum.</li>\n<li>Etiam massa libero, lacinia at, commodo in, tincidunt a, purus.</li>\n<li>Praesent volutpat eros quis enim blandit tincidunt.</li>\n<li>Aenean eu libero nec lectus ultricies laoreet. Donec rutrum, nisi vel egestas ultrices, ipsum urna sagittis libero, vitae vestibulum dui dolor vel velit.</li>\n</ol>",
          "post_title": "A Post With an Ordered List",
          "post_excerpt": "",
          "post_status": "publish",
          "comment_status": "open",
          "ping_status": "open",
          "post_password": "",
          "post_name": "a-post-with-an-ordered-list",
          "to_ping": "",
          "pinged": "",
          "post_modified": "2008-09-11 22:20:17",
          "post_modified_gmt": "2008-09-12 03:20:17",
          "post_content_filtered": "",
          "post_parent": 0,
          "guid": "https://dev.danphilibin.com/wordpress/?p=55",
          "menu_order": 0,
          "post_type": "post",
          "post_mime_type": "",
          "comment_count": "1",
          "filter": "raw"
        },
        {
          "ID": 5,
          "post_author": "1",
          "post_date": "2008-08-02 19:52:26",
          "post_date_gmt": "2008-08-03 00:52:26",
          "post_content": "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed eleifend urna eu sapien. Quisque posuere nunc eu massa. Praesent bibendum lorem non leo. Morbi volutpat, urna eu fermentum rutrum, ligula lacus interdum mauris, ac pulvinar libero pede a enim. Etiam commodo malesuada ante. Donec nec ligula. Curabitur mollis semper diam. <!--more-->\n\nDuis viverra nibh a felis condimentum pretium. Nullam tristique lacus non purus. Donec vel felis. Etiam et sapien. Pellentesque nec quam a justo tincidunt laoreet. Aenean id enim. Donec lorem arcu, eleifend venenatis, rhoncus mollis, semper at, dui. Praesent velit tellus, adipiscing et, blandit convallis, dictum at, dui. Integer suscipit tortor in orci. Phasellus consequat. Quisque dictum convallis pede.\n\nMauris viverra scelerisque mauris. Nulla facilisis, elit malesuada pretium egestas, dolor arcu commodo est, at egestas massa tortor ut ante. Etiam eget libero. Aenean pretium, tellus sed sodales semper, turpis purus aliquet orci, pulvinar ornare odio tortor sit amet dui.\n\nAenean id orci. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vivamus magna. Mauris tincidunt iaculis enim. Duis a mi vitae sapien dapibus tincidunt. Proin metus.\n\nProin cursus, libero non auctor faucibus, urna mi vestibulum orci, sit amet fermentum nibh purus eget enim. Aenean aliquet ligula nec nulla. Praesent sit amet lorem vitae massa hendrerit auctor. Sed sit amet urna. Aenean sapien nunc, imperdiet a, pharetra in, consequat eu, neque. Phasellus vel sem gravida augue consequat tempor. Curabitur eget mauris at pede varius facilisis.\n\nMorbi ut sapien. Morbi arcu mauris, suscipit congue, placerat sit amet, suscipit a, ante. Donec aliquet dui ac nunc. Mauris magna quam, aliquet quis, viverra eu, fringilla eget, purus. Donec tristique pretium sem.",
          "post_title": "A Simple Post with Text",
          "post_excerpt": "",
          "post_status": "publish",
          "comment_status": "open",
          "ping_status": "open",
          "post_password": "",
          "post_name": "a-simple-post-with-text",
          "to_ping": "",
          "pinged": "",
          "post_modified": "2008-08-02 19:52:26",
          "post_modified_gmt": "2008-08-03 00:52:26",
          "post_content_filtered": "",
          "post_parent": 0,
          "guid": "https://dev.danphilibin.com/wordpress/?p=22",
          "menu_order": 0,
          "post_type": "post",
          "post_mime_type": "",
          "comment_count": "0",
          "filter": "raw"
        }
      ],
      "post_count": 2,
      "current_post": -1,
      "in_the_loop": false,
      "post": {
        "ID": 37,
        "post_author": "1",
        "post_date": "2008-09-11 22:20:17",
        "post_date_gmt": "2008-09-12 03:20:17",
        "post_content": "Nulla sagittis convallis arcu. Sed sed nunc. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo. Fusce in est. Sed nec diam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Quisque semper nibh eget nibh. Sed tempor. Fusce erat.\n\n<h3>An Ordered List</h3>\n\n<ol>\n<li>Vestibulum in mauris semper tortor interdum ultrices.</li>\n<li>Sed vel lorem et justo laoreet bibendum. Donec dictum.</li>\n<li>Etiam massa libero, lacinia at, commodo in, tincidunt a, purus.</li>\n<li>Praesent volutpat eros quis enim blandit tincidunt.</li>\n<li>Aenean eu libero nec lectus ultricies laoreet. Donec rutrum, nisi vel egestas ultrices, ipsum urna sagittis libero, vitae vestibulum dui dolor vel velit.</li>\n</ol>",
        "post_title": "A Post With an Ordered List",
        "post_excerpt": "",
        "post_status": "publish",
        "comment_status": "open",
        "ping_status": "open",
        "post_password": "",
        "post_name": "a-post-with-an-ordered-list",
        "to_ping": "",
        "pinged": "",
        "post_modified": "2008-09-11 22:20:17",
        "post_modified_gmt": "2008-09-12 03:20:17",
        "post_content_filtered": "",
        "post_parent": 0,
        "guid": "https://dev.danphilibin.com/wordpress/?p=55",
        "menu_order": 0,
        "post_type": "post",
        "post_mime_type": "",
        "comment_count": "1",
        "filter": "raw"
      },
      "comment_count": 0,
      "current_comment": -1,
      "found_posts": "2",
      "max_num_pages": 1,
      "max_num_comment_pages": 0,
      "is_single": false,
      "is_preview": false,
      "is_page": false,
      "is_archive": false,
      "is_date": false,
      "is_year": false,
      "is_month": false,
      "is_day": false,
      "is_time": false,
      "is_author": false,
      "is_category": false,
      "is_tag": false,
      "is_tax": false,
      "is_search": false,
      "is_feed": false,
      "is_comment_feed": false,
      "is_trackback": false,
      "is_home": true,
      "is_404": false,
      "is_comments_popup": false,
      "is_paged": false,
      "is_admin": false,
      "is_attachment": false,
      "is_singular": false,
      "is_robots": false,
      "is_posts_page": false,
      "is_post_type_archive": false,
      "thumbnails_cached": false
    }
    Plugin Author grosbouff

    (@grosbouff)

    There is now a “sort topics by votes” link on single forum pages in 1.1.0.

    Hi there,

    I am a total noob and I know nothing of php and sql. How and where do I exactly add this “query” into wordpress to make it sort the posts by votes? Your guidance would really help a lot.

    Have a great new year!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘sort topics according to votes’ is closed to new replies.