Scenario is, you have a page
http://example.com/popular/, and you want to add custom query variable for the page which can be retrieve using
get_query_var() function to modify template or filter query. So a request to
http://example.com/popular/music/2014/usa will make new query variables – (<
popular_category = music,
popular_year = 2014,
popular_location = usa) available for you.
A solution can be achieved using
add_rewrite_tag() function, but there is a more easier way which will only use one function to make the custom query variable available for the specific page, and won’t effect any other pages or anything.
Above function processes has been commented for better understanding. Now we can use
get_query_var('popular_location') to retrieve specific url custom query variable.
We will create a list of posts based on our custom query variable. For that, first we will create a shortcode which will generate content using the custom query variable. And then place the shortcode on the Popular page.
Ok, now if you use the shortcode
[popular_posts] in your Page (Popular), you should see a list. Try manually entering url appending the popular page and check the results. You can also add some links to you nav menu using direct url of a popular page for quick access by you or user.
For ordering/sorting posts, we have used comment_count. Perhaps you could read this article to save posts social share amount & order by share count.