public
Last active

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
// sfw endpoint
add_action( 'init', 'add_sfw_endpoint' );
function add_sfw_endpoint()
{
add_rewrite_endpoint( 'sfw', EP_ALL );
}
 
add_action( 'pre_get_posts', 'sfw_pre_get_posts' );
function sfw_pre_get_posts($query)
{
global $wp_query;
if (isset($wp_query->query_vars['sfw']))
{
$query->query_vars['tax_query'][] = array(
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => 'nsfw',
'operator' => 'NOT IN',
);
if ( ! empty($wp_query->query_vars['sfw']))
{
$vars = explode('/', $wp_query->query_vars['sfw']);
foreach ($vars as $i => $var)
{
if ($i % 2 == 0)
{
if ( ! $wp_query->is_singular() && $var == 'page')
{
$var = 'paged';
if ($vars[$i+1] > 1)
{
$wp_query->is_paged = true;
}
}
$wp_query->query_vars[$var] = $vars[$i+1];
}
}
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.