Forums › Forums › Search & Filter Pro › post types in alphabetical order
Tagged: ajax, alphabetical, masonry
- This topic has 8 replies, 2 voices, and was last updated 7 years, 12 months ago by Trevor.
-
Anonymous(Private) November 17, 2016 at 7:29 pm #70952
we are using the Search and filter for several post types and it is working magnificently! (also got masonry working for the results!)
The question I would like to ask, is:
Can we reorder the post types into alphabetical order?
(I can provide a link if need be)
We are using AJAX results using the shortcode.Thank you for your time, and such a great plug in!
Anonymous(Private) November 18, 2016 at 1:10 pm #71049I would have to say that I did try to change the order of the custom post types by changing their menu positions.(5-100) and that did not work, but thought it might since they are in the order that they are in my admin menu. Maybe that will help Ross.
Anonymous(Private) November 18, 2016 at 1:15 pm #71051This is how I got the masonry working:
(function ( $ ) { "use strict"; $(function () { //detects the start of an ajax request being made $(document).on("sf:ajaxstart", ".searchandfilter", function(){ console.log("ajax start"); }); //detects when the ajax request has finished and the content has been updated // - add scripts that apply to your results here $(document).on("sf:ajaxfinish", ".searchandfilter", function(){ console.log("ajax complete"); $('#ms-container').imagesLoaded( function() { var container = document.querySelector('#ms-container'); var msnry = new Masonry( container, { itemSelector: '.ms-item', columnWidth: '.ms-item', isAnimated: true, }); }); // this is to change the text label in search box --this can be omitted $('label.sf-label-checkbox').each(function() { var text = $(this).text(); $(this).text(text.replace('TL Articles', 'Thought Leadership')); }); // end of change the text label in search box --this can be omitted console.log("masonry complete"); //so load your lightbox or JS scripts here again }); //an event fired when S&F is initialised and S&F scripts have been loaded $(document).on("sf:init", ".searchandfilter", function(){ console.log("S&F JS initialised"); }); }); }(jQuery));
Anonymous(Private) November 28, 2016 at 9:20 pm #72714Do you happen to know where these are called in?
I believe it is currently being populated by Post Type ID. (or is the way that WordPress does it), and I would think that this could be done kind of easily, (but I am no WP or Search and Filter expert)
Is it in post_type.php, in the public > includes > fields directory?
I found this code online, but am not sure how to apply it, but you guys might!
add_action( 'pre_get_posts', custom-post-slug_order' ); /** * Change order of custom post type to alphabetical ascending */ function custom-post-slug_order( $query ) { // check if we're in admin, if not exit if ( ! is_admin ) { return; } $post_type = $query->get('post_type'); if ( $post_type == custom-post-slug) { /* Post Column: e.g. title */ if ( $query->get( 'orderby' ) == '' ) { $query->set( 'orderby', 'title' ); } /* Post Order: ASC / DESC */ if( $query->get( 'order' ) == '' ){ $query->set( 'order', 'ASC' ); } } }
I hope to get this working as soon as possible.
Anonymous(Private) November 29, 2016 at 3:56 pm #72872After looking into getting this working sooner, than later, I found a solution!
A small little JS plugin called Tiny Sort.
Once the js file is loaded, I used the following code within the sf-pro-ajax-events.js file:$(function() { tinysort('ul>li.sf-level-0'); console.log("tiny sort restarted after ajax"); });
This will load anytime after the ajax has finished.
You can get the tiny sort code here:
tinysort.sjeiti.com -
AuthorPosts