• Resolved kazack

    (@kazack)


    How can I order posts by views??

    For my theme this code works well, can I do thomething like this with your plugin:

    function base6_search_filter( $query ) {
    if( $query->is_category ) {
    $query->set( ‘v_sortby’ , ‘views’ );
    $query->set( ‘v_orderby’ , ‘desc’ );
    add_filter(‘posts_fields’, ‘views_fields’);
    add_filter(‘posts_join’, ‘views_join’);
    add_filter(‘posts_where’, ‘views_where’);
    add_filter(‘posts_orderby’, ‘views_orderby’);
    }
    } add_filter( ‘pre_get_posts’ , ‘base6_search_filter’ );

Viewing 1 replies (of 1 total)
  • Thread Starter kazack

    (@kazack)

    I did it 🙂

    Edit json-rest-api/lib/class-wp-json-posts.php (WP REST API plugin):
    1. Find line:
    public function get_posts( $filter = array(), $context = ‘view’, $type = ‘post’, $page = 1) {
    $query = array(
    );
    2. Replace with:
    public function get_posts( $filter = array(), $context = ‘view’, $type = ‘post’, $page = 1) {
    $query = array(
    ‘v_sortby’ => ‘views’,
    ‘v_orderby’ => ‘desc’
    );
    3. Also plugin WP-PostViews by Lester ‘GaMerZ’ Chan should be installed

    • This reply was modified 8 years ago by kazack.
Viewing 1 replies (of 1 total)

The topic ‘Order by’ is closed to new replies.