[DiscordArchive] it's true?
[DiscordArchive] it's true?
Archived author: Guybrush • Posted: 2023-01-04T15:42:46.526000+00:00
Original source
```php
function wpb_rand_posts()
{
$args = array(
'post_type' => 'post',
'orderby' => 'rand',
'posts_per_page' => 5,
'cat' => 418, // dungeon category
);
$the_query = new WP_Query($args);
if (!$the_query->have_posts()) {
return "No posts found";
}
// actually randomize
shuffle($the_query->posts);
$string .= '<ul>';
while ($the_query->have_posts()) {
$the_query->the_post();
$string .= '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
}
$string .= '</ul>';
wp_reset_postdata();
return $string;
}
add_shortcode('wpb-random-posts', 'wpb_rand_posts');
add_filter('widget_text', 'do_shortcode');
```
Archived author: Guybrush • Posted: 2023-01-04T15:42:57.569000+00:00
Original source
offered some unsolicited refactoring for you
Archived author: Guybrush • Posted: 2023-01-04T15:43:14.040000+00:00
Original source
but it's still doing inline html, which is gross even for wordpress
Archived author: Guybrush • Posted: 2023-01-04T15:43:17.936000+00:00
Original source
but w/e
Archived author: blacknightt • Posted: 2023-01-04T15:56:53.177000+00:00
Original source
does not work right
Archived author: Guybrush • Posted: 2023-01-04T15:58:36.335000+00:00
Original source
what does it do exactly