Display ads by location

I have recently purchased a WordPress theme,and built a website with directory listing. On the Homepage there is a listing with locations, and at the moment they are listed in ascending order.

I have managed to figure out where is the script which controls this section, what I would like to do is to display the locations where the highest number of adverts are.

This is the bit of code which I believe is displaying it:

<?php
$location_counter = $redux_demo['home-location-counter'];

$locations = get_terms(

    'location', 

    array(

        'parent' => 0,

        'order'=> 'ASC',

        'number'=> $location_counter,

        'empty'=> 1

    )   
);

//print_r($locations);

//exit();

foreach ($locations as $location) {

    if(!empty($location)){

?>

How could I re-write this section to show the locations according to the highest number of adverts added to a particular city? If anyone could give me an advice, it would be great. I have tried with the support, but they were not very helpful.

Solutions

You can get what you want by doing this:

'order'=> 'ASC', 'orderby' => 'count'

This will order the result of get_terms by number of posts each term has

Similar questions

Multiple GPT ads in same page display only once
i need display multiple ads on one page with this code: If i use this code twice or more on page, i get error: Exception in queued GPT command TypeError: Cannot read property 'addService' of null Code must be same, customer want paste it to page via shortcode in cms. How to solve this? Thanks
WordPress: Display Google Ads to guest users only
I have a WordPress website and a registration system in it. Lets say I have the following Google Ad example: How can I display the Ad only to guest users? I've been stuck with this for days. Is there a plugin? or can I edit the user roles somewhere?
Offering Ads Dependent on Visitor Type?
I wish to be able to give different ads to visitors of different "types". For example: People from country X will get one ad, while people from country Y will get no ads. First time visitors will get an ad. Returning visitors won't. The ad can be either google ads or something else. Any plugin or hack to do it?
Ads Restricted on WordPress.com?
I am creating a WordPress blog myself - downloading it and installing it myself - as well as buying a domain name and hosting it using something like simplynames.com. I read somewhere though that you can't have adverts on a WordPress blog? Something to do with .org or .com - is this irrelevant if I am hosting elsewhere?? Thanks
How can I add Google ads to my home page?
Guys I know this is the stupid question but need a little help, I need to put ads on my homepage as I have on my post page: These are the ads I get on my post page (i.e single.php). I also want the same thing on my home page over here: I tried using a <div> tag like I did on single.php, but it is not working.
Specific and Different Ads for each Post?
I am working with a magazine client who sells adversiting offline in their magazine and now has a WordPress online magazine. Each of their stories is broken into different posts, and they are using the Wootheme Spectrum. They want the ads in the magazine to correspond to the ads online. So if Story B has Ad Z, then online, Post B should have Ad Z i...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.