I was trying to display profile photo of community user. I don't want to apply query on user object and also I found a field on Contact i.e. PhotoURL, i have uploaded the profile photo of the community user, but when I executed a query from devConsole on the respective record the field is not populated and is blank. how can i get the photoUrl directly from the contact?
For each community user a user record exists which is tagged to the contact. You can query
User.FullPhotoUrl field to get the photo.
In case you don't want to query on user you will either need to store the photo url from user to contact or use Connect API, both of them are more time consuming.
photoUrl on Contact is not used to store Community User profile image. From the docs-
Path to be combined with the URL of a Salesforce instance (Example: https://yourInstance.salesforce.com/) to generate a URL to request the social network profile image associated with the contact. Generated URL returns an HTTP redirect (code 302) to the social network profile image for the contact.
Empty if Social Accounts and Contacts isn't enabled or if Social Accounts and Contacts is disabled for the requesting user.