Home Forums Add-ons Repeater Field Repeater Plugin – Group By Help Reply To: Repeater Plugin – Group By Help

  • $plfsByState = $wpdb->get_results("
        select pm.meta_value as state, count(*) as postcount
          from $wpdb->posts p
               join $wpdb->postmeta pm on p.ID = pm.post_id
         where p.post_type = 'plfmaps'
           and p.post_status = 'publish'
      group by state
      order by state ASC");

    This gives me way too much data…And doesnt exactly work. This basically returns everything. I’m seeing div with the address, city, state. How can i modify this query to only show the states?

    Where I am getting mixed up is the meta_key value for the location_state actually looks like this in the database table “locations_0_state” and “locations_1_state” — any ideas on this one? I feel like I am really close, but I’m missing something.