Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
// 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];
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.