-
Author
-
August 7, 2017 at 18:55 #169864kffanerParticipant
i could not find a working answer to this, i even tried other plugins, but i want to be able to add an option to sort articles by LIKES.
For example, when i use KLE POSTS element, i want to be able to specify in the query to sort the posts by LIKES so that the ones with the most likes appear first.
Can you please help me make this happen? I would appreciate any suggestions/support with this.
August 7, 2017 at 21:41 #169900LauraModeratorHello, will assign the ticket to a higher support level who can help and advise you in your query.
Thanks! ?Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionLaura Solanes - Graphic Designer and Web Designer
Please be patient as I try to answer each topic as fast as i can.
If you like the theme or the support you've received please consider leaving us a review on Themeforest!
Always happy to help you 🙂
August 7, 2017 at 21:43 #169901kffanerParticipantsounds good, thanks, i am a little familiar with JQ and PHP editing, if that helps in helping me with this issue hehe
August 9, 2017 at 19:57 #170091RaduModeratorHi,
I’ve tried to make a function that filters that but I cannot make it works, it require more time and i will try again this tomorrow, here are some resources if you are familiar with php maybe you will work around
https://wordpress.stackexchange.com/questions/169999/multiple-orderby-in-pre-get-posts-action
Cheers
R.Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionAugust 9, 2017 at 20:35 #170096kffanerParticipanthi,
thanks, please let me know if you can make it work, if not ill have to try to figure it out but im betting you know more on php than i do.
August 11, 2017 at 18:34 #170285RaduModeratorHi,
Just add this php code to wp-content/themes/kleo-child/functions.php
COPY CODEadd_filter( 'pre_get_posts', 'show_posts_by_kleo_likes' ); function show_posts_by_kleo_likes( $query ) { $query->set( 'meta_key', '_item_likes' ); $query->set( 'orderby', 'meta_value_num' ); $query->set( 'order', 'DESC' ); return $query; }
That’s all
Cheers
R.Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionAugust 11, 2017 at 18:39 #170286kffanerParticipantweird, if i add this code it causes the front page to disappear and be removed Oo any ideas?
August 11, 2017 at 18:42 #170287kffanerParticipantit causes a bunch of pages to disappear including the default buddypress pages. no idea why, can we troubleshoot this?
August 11, 2017 at 18:52 #170289RaduModeratorTry to enable parent theme then back the child theme
Let me know
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionAugust 11, 2017 at 19:01 #170292kffanerParticipanttried, when i do that each time when switching to child theme (where the changes were made) it gives me 404 for the pages that are supposed to be there.
August 11, 2017 at 19:40 #170296kffanerParticipanti changed (on theme settings) words “Likes” to “prayers” but i don’t think that should have any impact on this, those are just labels…
August 15, 2017 at 19:16 #170738RaduModeratorHi,
The edit likes text options not affecting that.
Just replace the code with this one
COPY CODEadd_filter( 'pre_get_posts', 'show_posts_by_kleo_likes' ); function show_posts_by_kleo_likes( $query ) { if(is_home()) { $query->set('meta_key', '_item_likes'); $query->set('orderby', 'meta_value_num'); $query->set('order', 'DESC'); return $query; } }
Will run only on blog/ page
Cheers
RHi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionAugust 15, 2017 at 19:46 #170740kffanerParticipantnope, did not work, the option on the drop down menu is not there. I pasted the code into child themes function.php file and i switched back and forward from child theme to main theme and back to child theme. Still no option.
Attachments:
You must be logged in to view attached files.August 18, 2017 at 16:37 #171063RaduModeratorHi,
The snippet will not add the option there, it will sort the posts from the page (blog page) by likes.
So, the previous code will work only on blog, page, if you want to sort the posts by Cleo likes on other page just use the next code instead.
COPY CODEadd_filter( 'pre_get_posts', 'show_posts_by_kleo_likes' ); function show_posts_by_kleo_likes( $query ) { if(is_page(array ( 'mypage-slug', 'my-second-page-slug', 'thirdpage-slug' ) )) { $query->set('meta_key', '_item_likes'); $query->set('orderby', 'meta_value_num'); $query->set('order', 'DESC'); return $query; } }
So the post will be sort only in those page slugs ‘mypage-slug’, ‘my-second-page-slug’, ‘thirdpage-slug’ eddit those as you need.
Cheers
RHi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionAugust 18, 2017 at 16:38 #171064kffanerParticipanti dont understand, if it does not give the option, then how do i know what to choose or when it will do this? it will override any option i choose on the widget, if i define the page slug on the code?
August 18, 2017 at 16:45 #171065kffanerParticipanti want to use widgets to display posts by likes and another to display by publish date. so if i use this code and it overrides any options i set on a particular page, then it will sort all of them by likes?
August 21, 2017 at 18:28 #171287RaduModeratorHi,
Ah I see,
The snippet just arranges the posts that are displayed on the blog page.. but this will not work if you want to sort a loop by likes and another one by something else.
For the moment there is no quick solution to add the sort option by likes in the visual composer posts element.
Cheers
R.Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionAugust 21, 2017 at 18:59 #171298kffanerParticipanti strongly suggest adding that feature to the theme. Its something that there arent a lot of out there (for whatever reason) and its something that pretty much everyone using this theme would be able to incorporate and would do so right away. It makes little sense to have a function for “likes” but no function to sort posts by those likes.
August 22, 2017 at 17:45 #171425RaduModeratorHi,
I will take your suggestion and I will add it to our improvement list when we do something we will let you know
Cheers
R.Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution -
AuthorPosts
You must be logged in to reply to this topic.