I am making a homepage for the band.
I would like to display a list of past live performances by month.
The live schedule can be entered with the date picker as "live_date" in Advanced Custom Fields.

By the way, "Future live schedule" is a custom post type "live"
Created at.
"Past live list" is a fixed page
It is created in.

The problem i am having

The following articles
I tried to make it with reference to, but it was not displayed at the stage of "Display select box for narrowing down by date of custom field" and I stumbled.

Corresponding source code

I added the code as follows.

Am I doing something wrong?
I would appreciate it if you could teach me.

Add the following to functions.php

function my_get_month_archives ($args ='') {
    global $wpdb, $wp_locale;
    $defaults = array (
        'date_field' =>'live_date', // Describe the field name of the custom field
        'format' =>'html',
        'echo' =>true,
        'limit' =>'',
        'before' =>'',
        'after' =>'',
        'show_post_count' =>true,
    $r = wp_parse_args ($args, $defaults);
    extract ($r, EXTR_SKIP);
    if (''! = $limit) {
        $limit = absint ($limit);
        $limit ='LIMIT'. $limit;
    $field ='m.meta_value';
    $select = "SELECT SUBSTRING ($field, 1,4) AS` year`, SUBSTRING ($field, 6,2) AS `month`, count (p.ID) AS posts";
    $where = "WHERE p.post_type ='post' AND p.post_status ='publish'";
    $where. = $wpdb->prepare ('AND m.meta_key =% s', $date_field);
    $join = "INNER JOIN $wpdb->postmeta AS m ON m.post_id = p.ID";
    $where = apply_filters ('getarchives_where', $where, $r);
    $join = apply_filters ('getarchives_join', $join, $r);
    $output ='';
    $query = "$select FROM $wpdb->posts AS p $join $where GROUP BY SUBSTRING ($field, 1,4), SUBSTRING ($field, 6,2) ORDER BY $field DESC $limit";
    $key = md5 ($query);
    $cache = wp_cache_get ('my_get_month_archives','general');
    if (! isset ($cache [$key])) {
        $arcresults = $wpdb->get_results ($query);
        $cache [$key] = $arcresults;
        wp_cache_set ('my_get_month_archives', $cache,'general');
    } else {
        $arcresults = $cache [$key];
    if ($arcresults) {
        $afterafter = $after;
        foreach ((array) $arcresults as $arcresult) {
            $url = add_query_arg (array ('meta_key' =>$date_field), get_month_link ($arcresult->year, $arcresult->month));
            $text = sprintf ('% d', $arcresult->year).'Year'. Sprintf ('% d', $arcresult->month).'Month';
                        $output. ='<option value = "'. $url.'">'. $Text.'</Option>';
    if ($echo)
        echo $output;
    else else
        return $output;

Add the following to page-pastlive.php

<select name = "archive-dropdown" onChange ='document.location.href = this.options [this.selectedIndex] .value;'>
  <option value = "">Narrow down by age</option>
  <? php
        my_get_month_archives (array (
        'date_field' =>'live_date', // Describe the field name of the custom field
  • Answer # 1

    I just looked at the sauce,

    $where = "WHERE p.post_type ='post' AND p.post_status ='publish'";

    This part is

    $where = "WHERE p.post_type ='live' AND p.post_status ='publish'";

    Isn't it?