Adding page subdirectory dynamically, as like buddypress does

This should do what you want: add_action(‘generate_rewrite_rules’, ‘wpse128082_add_rewrite_rule’); function wpse128082_add_rewrite_rule($wp_rewrite) { $new_rules = array( ‘^charts/(.*)’ => ‘index.php?pagename=charts&something=’.$wp_rewrite->preg_index(1), ); $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; } add_filter(‘query_vars’, ‘wpse128082_add_query_var’); function wpse128082_add_query_var($query_vars) { $query_vars[] = ‘something’; return $query_vars; } On your Charts page, you can access the new query var with get_query_var(‘something’).

Ger posts from similar tags and categories

Below is the solution for your problem If my understanding is right! if ($tags) { $tag_ids = array(); foreach($tags as $single_tag) $tag_ids[] = $single_tag->term_id; $args=array( ‘tag__in’ => $tag_ids, ‘post__not_in’ => array($post->ID), ‘showposts’=> 5, ); if( count($args) < 5 ) { $n = 5 – count($args); //to get posts based on the category if ($categories) { … Read more