Support

Account

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

  • Does this look correct? I’m getting good results with it. So, i think i got it.

    $plfsByState = $wpdb->get_results($wpdb->prepare( 
    "
    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'
    AND meta_key LIKE %s 
    AND meta_value LIKE %s 
    GROUP BY meta_value ASC",
    'locations_%_state',
    '%',
    ""		
    ));

    Thanks for your help. This appears to be showing all of the states, grouped by the state and then showing a count of the total number of results from that state. This is a little tricky with those % signs.

    Question about the query. At the very end, ‘locations_%_state” is the meta_key, and ‘%’ is the meta_value, so then what is the “” at the very end? What does that do?