• Resolved skyline521

    (@skyline521)


    Is there any way to add a custom “Sort By” option? Client wants to rank listings. I found a way by just adding numbers to the title “1.,2.,3.,etc” but is there a way to hide it from the front end and have listings displayed in a particular order without wasting “featured” or “ranked featured” listings? We are on lifetime pro version.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi @skyline521,

    One idea I have is you can have a custom number field and then define the order on that field (1,2,3…) and then modify the query to orderby those meta values. We have two filter hooks that you can use to modify the argument sent by Directorist to perform a WP_Query, they are:
    atbdp_all_listings_query_arguments
    atbdp_listing_search_query_argument

    Here is more about the order and orderby: https://developer.www.ads-software.com/reference/classes/wp_query/#order-orderby-parameters

    Regards,
    Mahdi.

    Thread Starter skyline521

    (@skyline521)

    Thanks @m4hd1bd, where exactly do I modify the argument? in the plugin files?

    Hi @skyline521,

    No, you usually write codes on your theme’s functions.php or you may use a Code Snippet plugin. Here’s a guide on how Filter Hooks (the two hooks I mentioned are filter hooks, they consists of one arguments which is an array and get passed as the argument list to WP_Query call) works, it sounds like you’re not much familiar with it: https://docs.presscustomizr.com/article/26-wordpress-actions-filters-and-hooks-a-guide-for-non-developers#:~:text=to%20you%20now.-,Filters%3A,-When%20Jack%20comes

    Regards,
    Mahdi.

    • This reply was modified 2 years, 2 months ago by Mahdi.
    Thread Starter skyline521

    (@skyline521)

    @m4hd1bd okay so I tried using a custom field and using this php snippet, but for some reason it’s pulling up blog posts and not listings? urc_rank is the custom field and it simply has a number value.

    add_filter('atbdp_all_listings_query_arguments', 'ordby');
    function ordby(){
    $args = array(
    'post_type' => 'at_biz_dir',
    'orderby' => 'meta_value_num',
    'meta_key' => 'urc_rank',
    'order' => 'ASC',
    );
    }

    Thread Starter skyline521

    (@skyline521)

    @m4hd1bd nevermind the above. I corrected that issue, but now i’ve got another issue where if I go to another page of listings, it’s starting over from the beginning again (1, 2, 3, 4)

    add_filter('atbdp_all_listings_query_arguments', 'ordby');
    function ordby(){
    $args = array(
    'post_type' => 'at_biz_dir',
    'orderby' => 'meta_value_num',
    'meta_key' => 'urc_rank',
    'order' => 'ASC',
    );
    return $args;
    }

    • This reply was modified 1 year, 11 months ago by skyline521.
    Thread Starter skyline521

    (@skyline521)

    I answered my own issue yet again. for anyone looking to do this in the future, below I have my PHP snippet for ordering directory listings by custom field for both listings and search, respectively.

    add_filter( 'atbdp_all_listings_query_arguments', 'ordby' );
    function ordby( $args ) {
    $args['post_type'] = 'at_biz_dir';
    $args['orderby'] = 'meta_value_num';
    $args['meta_key'] = 'urc_rank';
    $args['order'] = 'ASC';
    return $args;
    }

    add_filter( 'atbdp_listing_search_query_argument', 'ordby' );
    function searchordby( $args ) {
    $args['post_type'] = 'at_biz_dir';
    $args['orderby'] = 'meta_value_num';
    $args['meta_key'] = 'urc_rank';
    $args['order'] = 'ASC';
    return $args;
    }

    Hey @skyline521,

    Glad to know that you figured it out. One improvement would be to remove the line where you set the post_type, it is already set, and you don’t necessarily need to set it again.

    Oh, another thing is, you can define the function once and call it on both hooks, since they are both doing the same thing basically. So your code will look like this basically:

    add_filter( 'atbdp_all_listings_query_arguments', 'ordby' );
    add_filter( 'atbdp_listing_search_query_argument', 'ordby' );
    function ordby( $args ) {
    $args['orderby'] = 'meta_value_num';
    $args['meta_key'] = 'urc_rank';
    $args['order'] = 'ASC';
    return $args;
    }

    Anyway, good work. Let me know if you need help with anything else.

    Regards,

    Mahdi.

    • This reply was modified 1 year, 11 months ago by Mahdi.
    • This reply was modified 1 year, 11 months ago by Mahdi.

    hey @m4hd1bd,

    I had multidirectory activated, what if i only want to order this way just one of all my directory types? how can i filter that way?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Custom Sort By Option’ is closed to new replies.