How to make a wordpress loop file that displays posts based on certain conditions

This is more of a logical problem.

Lets say you stored location (City/address/Lat-long(Best would be Lat/long) of user in a custom field (There should be a standard way to assign locations to users throughout the site). you want to query posts from users which are near this particular user.

  • Get custom field value of location for this user.
  • Convert this location to Lat-long (So that you can query google map)
  • Find locations near this particular location by using Google Maps API. Use this page to know how to do that. Also you can find many other ways of doing this by googling.
  • Get results from google and convert them in that standard form you are using on your site.
  • Now you can query WordPress (Using meta query) to get all the users living in cities you just found.
  • After getting users you can get posts for each user.

If you are trying to get posts from users of same country that would be quiet easy.
You can use meta query for this task. Try below arguments in WP_Query:

$args = array(
    'post_type'=>'post',
    'meta_query'=>array(
        'key'=>'country',
        'value'=> $country, //$country is a variable with country's name
        'type'=>'CHAR'
        'compare'=>'='
        ),
);
$query = new WP_Query($args);

To learn more about meta you can use WordPress CodeX.

To see all arguments of WP Query use this link.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)