• Dear all,
    I’m trying to add a sort option in my FacetWP that sorts results first by date (oldest post first) and then by a custom field I created called “Points”, that is always a number. I’m able to do it either/or, but I’m struggling to make both work simultaneosly. This is my code:

    add_filter( 'facetwp_sort_options', function( $options, $params ) {
        $options['points_desc'] = array(
            'label' => 'Points (Highest)',
            'query_args' => array(
                'orderby' => 'meta_value_num',
                'meta_key' => 'points',
                'order' => 'DESC',
            )
        );
        return $options;
    }, 10, 2 );

    I’m trying to replicate this here: GitHub, but I’m not being able to adapt it to my needs. Any help? Thanks in advance!

    • This topic was modified 4 years, 5 months ago by talestomaz.
Viewing 1 replies (of 1 total)
  • Plugin Author Pixelbart

    (@pixelbart)

    @talestomaz

    The two meta-fields of Helpful are: helpful-pro and helpful-contra

    How you can now use FaceWP to control multiple filters at the same time, I don’t know. You’ll have to ask the FaceWP support.

    However, Helpful only updates the content in the meta fields if you access the posts in the wp-admin or in the post overview directly in the wp-admin.

    Otherwise, you must update the meta fields so that the current values are always used.

    You can see how Helpful updates the meta fields here:

    // Pro

    $pro = Helpful_Helper_Stats::getPro( $post_id );
    $pro = intval( $pro );
    update_post_meta( $post_id, 'helpful-pro', $pro );
    

    // Contra

    $contra = Helpful_Helper_Stats::getContra( $post_id );
    $contra = intval( $contra );
    update_post_meta( $post_id, 'helpful-contra', $contra );
    

    Source: https://github.com/pixelbart/helpful/blob/master/core/classes/class-helpful-table.php

    • This reply was modified 4 years, 5 months ago by Pixelbart.
    • This reply was modified 4 years, 5 months ago by Pixelbart.
Viewing 1 replies (of 1 total)
  • The topic ‘FacetWP: Sort by different criteria’ is closed to new replies.