Tell us what you are trying to do?
create a custom taxonomy (tags) and display all of them randomly.. ie. changing on refresh.
i have a custom post type called "social media posts" and in that a custom taxonomy (tags) called "sm hashtags" .. I need to randomly display all of the tags for the "social media posts" post type on a page, ie. each time the page is refreshed the tags are in a different order.
I cant seem to figure this out ..
is it possible?
Is there any documentation that you are following?
Is there a similar example that we can see?
What is the link to your site?
Hi Jen,
Thank you for contacting us and I'd be happy to assist.
The "wpv-post-taxonomy" can be used to show the attached taxonomy terms, but it can only show them ordered by name/title.
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-taxonomy
To show them in a random order, you'll need a custom shortcode that can show these terms, using the "get_the_terms" function:
https://developer.wordpress.org/reference/functions/get_the_terms/
Example:
add_shortcode( 'get_terms_random_order', 'get_terms_random_order_func');
function get_terms_random_order_func($atts) {
$a = shortcode_atts( array(
'type' => ''
), $atts );
$terms = get_the_terms( get_the_ID(), $a['type'] );
shuffle( $terms );
ob_start();
foreach ( $terms as $term ) {
echo $term->name.', ';
}
return ob_get_clean();
}
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through active theme's "functions.php" file.
After that, you'll be able to use this new shortcode on your single post pages, like this:
[get_terms_random_order type="slug-of-taxonomy"]
Note: You'll replace "slug-of-taxonomy" with the actual slug of your custom taxonomy "sm hashtags".
I hope this helps and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
regards,
Waqar
I did everything above, tested the code in the toolset editor and it said it was ran with no errors. but when i paste the short-code into a post it does not return any data.
the slug of my shortocde is sm-hashtag, so I am doing [get_terms_random_order type="sm-hashtag"].
I am placing this on a PAGE ... will this not work on a page ?
Can I use this shortcode in a view?
Thanks for writing back.
It is strange that the shortcode works on my test website, but not on yours. It should work on a single post/page and inside a view, alike.
Can you please share temporary admin login details, along with the link to a page where you tested this shortcode?
Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.