{"id":3271,"date":"2018-08-31T02:25:52","date_gmt":"2018-08-31T02:25:52","guid":{"rendered":"https:\/\/docs.contentviewspro.com\/?p=3271"},"modified":"2023-12-26T11:18:34","modified_gmt":"2023-12-26T11:18:34","password":"","slug":"live-filter-set-default-sort-option","status":"publish","type":"docs","link":"https:\/\/contentviewspro.com\/documentation\/article\/live-filter-set-default-sort-option\/","title":{"rendered":"Live Filter \u2013 set default sort option"},"content":{"rendered":"<p>With the Live Filter feature in Pro version, you can show sort options in frontend, to help your users to sort content themselves.<br \/>\nTo set the default sort option, please add this code to <strong>Custom JS<\/strong> field (the right textarea) in <a href=\"https:\/\/contentviewspro.com\/documentation\/wp-content\/uploads\/2018\/03\/Content-Views-_-Settings.png\">Content Views >> Settings<\/a> page:<\/p>\n<pre style=\"font-size:13px\">\n\/*Live Filter \u2013 set default sort option*\/\nif (!window.location.search) {\n    var viewid = 'VIEW_ID', default_sort = 'SORT_VALUE';\n    if ($('[data-sid=\"' + viewid + '\"] [name=\"_orderby\"]').val() == '') {\n        $('[data-sid=\"' + viewid + '\"] [name=\"_orderby\"]').val(default_sort).trigger('change');\n    }\n}\n<\/pre>\n<p>then:<\/p>\n<ul>\n<li>replace <strong>VIEW_ID<\/strong> with <a href=\"https:\/\/contentviewspro.com\/documentation\/article\/what-is-id-of-a-view\/\">ID of your View<\/a><\/li>\n<li>replace <strong>SORT_VALUE<\/strong> with the sort option you want to set as default, it can be <code>title<\/code>, <code>date<\/code>, or custom field key (to get correct custom field key, select that field from the live filter, the URL will change to <code>?_orderby=FIELD_KEY<\/code>, then copy the FIELD_KEY in URL).<\/li>\n<\/ul>\n<p>Best regards,<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the Live Filter feature in Pro version, you can show sort options in frontend, to help your users to sort content themselves. To set the default sort option, please add this code to Custom JS field (the right textarea) in Content Views >> Settings page: \/*Live Filter \u2013 set default sort option*\/ if (!window.location.search) &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/contentviewspro.com\/documentation\/article\/live-filter-set-default-sort-option\/\"> <span class=\"screen-reader-text\">Live Filter \u2013 set default sort option<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"doc_category":[46],"doc_tag":[36,35],"class_list":["post-3271","docs","type-docs","status-publish","hentry","doc_category-live-filter","doc_tag-custom-js","doc_tag-live-filter"],"year_month":"2026-09","word_count":148,"total_views":0,"reactions":{"happy":0,"normal":0,"sad":0},"author_info":{"name":"admin1","author_nicename":"admin1","author_url":"https:\/\/contentviewspro.com\/documentation\/author\/admin1\/"},"doc_category_info":[{"term_name":"Live Filter (Frontend Search &amp; Filter)","term_url":"https:\/\/contentviewspro.com\/documentation\/cats\/live-filter\/"}],"doc_tag_info":[{"term_name":"custom JS","term_url":"https:\/\/contentviewspro.com\/documentation\/tags\/custom-js\/"},{"term_name":"live filter","term_url":"https:\/\/contentviewspro.com\/documentation\/tags\/live-filter\/"}],"_links":{"self":[{"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/docs\/3271","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/comments?post=3271"}],"version-history":[{"count":1,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/docs\/3271\/revisions"}],"predecessor-version":[{"id":5250,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/docs\/3271\/revisions\/5250"}],"wp:attachment":[{"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/media?parent=3271"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/doc_category?post=3271"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/doc_tag?post=3271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}