Skip to content

Commit

Permalink
creates a random language template
Browse files Browse the repository at this point in the history
  • Loading branch information
FredericoAndrade committed Oct 10, 2024
1 parent 0eaf229 commit 2a80f24
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions wp-content/themes/blankslate-child/random-language.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/* Template Name: Random Language Redirect */

$args = array(
'post_type' => 'languages',
'posts_per_page' => -1,
'fields' => 'ids',
'meta_query' => array(
array(
'key' => 'speakers_recorded_count',
'value' => '0',
'compare' => '>',
'type' => 'NUMERIC'
)
)
);

$language_posts = get_posts($args);

if (!empty($language_posts)) {
$random_post_id = $language_posts[array_rand($language_posts)];
wp_redirect(get_permalink($random_post_id));
exit;
} else {
wp_redirect(home_url());
exit;
}

0 comments on commit 2a80f24

Please sign in to comment.