Gists

by mgibbs189 - 3 weeks ago

<?php

add_filter( 'facetwp_sort_options', function( $options, $params ) {
    $options['points_desc'] = [
        'label' => 'Points (Highest)',
        'query_args' => [
            'orderby' => [ 'date' => 'ASC', 'meta_value_num' => 'DESC' ],
            'meta_key' => 'points'
        ]
    ];
    return $options;
}, 10, 2 );
by mgibbs189 - 2 years ago

<?php

add_filter( 'facetwp_sort_options', function( $options, $params ) {
    $options['on_sale'] = array(
        'label' => 'On Sale',
        'query_args' => array(
            'sort_on_sale' => true,
            'meta_query' => array(
                array(
                    'key' => '_tilbud' // on sale
                ),
                array(
                    'key' => '_nypris' // price
                )
            )
        )
    );

    $options['price_asc'] = array(
        'label' => 'Price (lowest)',
        'query_args' => array(
            'meta_key' => '_nypris',
            'orderby' => 'meta_value_num',
            'order' => 'ASC'
         )
    );
    return $options;
}, 10, 2 );


// Sort by on sale (_tilbud), then by price (_nypris) ASC
add_filter( 'posts_orderby', function( $orderby, $wp_query ) {
    if ( isset( $wp_query->query_vars['sort_on_sale'] ) ) {
      $orderby = 'mt1.meta_value ASC, mt2.meta_value+0 ASC';
    }
    return $orderby;
}, 10, 2 );

by djrmom - 3 years ago

<?php

add_filter( 'facetwp_sort_options', function( $options, $params ) {
  $options['default']['query_args'] = array(
            'orderby' => 'menu_order',
            'order' => 'ASC',
        );
    return $options;
}, 10, 2 );

<?php
/* "ignore_custom_sort" => true to query args and use menu order instead */

return array(
"post_type" => "post",
"post_status" => "publish",
"orderby" => "menu_order",
"order" => "ASC",
"posts_per_page" => 10,
"ignore_custom_sort" => true
);
by mgibbs189 - 4 years ago

<?php
/**
 * Add a "Rating" sort option
 * 
 * @author David Nash <david@davidnash.com.au>
 */
function custom_wpjmr_after_save_comment_review( $comment_id ) {
    $wpjmr = WP_Job_Manager_Reviews::instance();
    $wpjmr->review->save_rating_average_post_meta( $comment_id );
}
add_action( 'wpjmr_after_save_comment_review', custom_wpjmr_after_save_comment_review' );


function my_facetwp_sort_options( $options, $params ) {
    $options['rating'] = array(
        'label' => 'Rating',
        'query_args' => array(
            'orderby' => 'meta_value_num', // sort by numerical custom field
            'meta_key' => '_average_rating', // required when sorting by custom fields
            'order' => 'DESC', // descending order
        )
    );
    return $options;
}
add_filter( 'facetwp_sort_options', 'my_facetwp_sort_options', 10, 2 );

by mgibbs189 - 5 years ago

<?php

function fwp_sortby_views( $options, $params ) {
    $options['views'] = array(
        'label' => 'Most Views',
        'query_args' => array(
            'orderby' => 'post_views',
        )
    );
    return $options;
}
add_filter( 'facetwp_sort_options', 'fwp_sortby_views', 10, 2 );
by mgibbs189 - 5 years ago

<?php

function my_facetwp_sort_options( $options, $params ) {
    if ( 'buy_sell_grid' == $params['template_name'] ) {
        unset( $options['distance'] );
    }
    return $options;
}
add_filter( 'facetwp_sort_options', 'my_facetwp_sort_options', 10, 2 );