Skip Navigation

[Résolu] Need to sort Taxonomies randomly

This support ticket is created Il y a 8 années et 3 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Marqué : 

This topic contains 1 réponse, has 2 voix.

Last updated by Luo Yang Il y a 8 années et 3 mois.

Assisted by: Luo Yang.

Auteur
Publications
#357318

I am trying to pick a video at random for playing on the homepage

I have not found any slider software to help me do this, but I am very close to finding a way using Views in combination with the Quode Slider which comes packed with the Bridge Theme.

Quote organises its slides using 'Sliders' as the taxonomy with member 'Slides' as the custom post type.

This site needs to play a full screen video on the homepage. It should select one from a choice of three or four at random. So visitors may see a different one when they return to the site.

I am therefore creating a series of Sliders containing a single video slide in each one. (The video slide is really a list of urls from AWS-hosted mp4, ogv and webm files which render the video).

Normally a slider is entered on a page in the Bridge theme by copying and pasting the full slider shortcode into a theme-generated custom field on the page. I have discovered that by writing a View to query the Slider Taxonomies, I can render the short code so it contains the 'slider' name like this - and it is this which renders on the page after I place the View shortcode, instead of the Slider shortcode, in the Slider custom field on the page:

     <wpv-loop>
          [qode_slider slider='[wpv-taxonomy-title]' auto_start='true' animation_type='slide' slide_animation='6000' height='' responsive_height='yes' anchor='top']
     </wpv-loop>

My theory is that by restricting the views output to 1 item and by sorting it randomly, we can then pluck a slide (video) at random for display on the homepage each time it is loaded.

However, I can not find a way to sort the View - when it queries Taxonomies - randomly.
I have the option to sort the results by TermID, TermSlug, TermName, PostCount, TermGroup and NoOrder. I have tried No Order but it still outputs the same slider every time.

Can you suggest how to complete the final part of this puzzle?

Many thanks
Tim

#357372

Dear Tim,

Views is using wordpress function get_terms() to query terms of custom taxonomy, see the document:
http://codex.wordpress.org/Function_Reference/get_terms
Possible Arguments
orderby
(string)
id
count
name - Default
slug
term_group - Not fully implemented (avoid using)
none

There isn't such an "random" option. I suggest you try this:
1) Create a view to query all terms of possible terms
2) use Views filter hook wpv_filter_taxonomy_post_query to pick only one random item and output it:
wpv_filter_taxonomy_post_query
When displaying a View listing taxonomy terms, this filter is applied to the arguments that will be passed to the get_terms() call.
https://toolset.com/documentation/user-guides/views-filters/wpv_filter_taxonomy_post_query/

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.