Title: get_month_link() question
Last modified: August 18, 2016

---

# get_month_link() question

 *  Resolved [Doodlebee](https://wordpress.org/support/users/doodlebee/)
 * (@doodlebee)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/get_month_link-question/)
 * Hey all –
 * I’m trying to do a “month by meta” url list, the idea is based upon [this post](http://wordpress.org/support/topic/86058?replies=18)
   here in the forums.
 * I believe I’m getting the query correct, because when I echo after each step,
   then my output is doing what it should be doing. What I have right now is this:
 *     ```
       } elseif ( 'catmonthly' == $type ) {
             $arcresults = $wpdb->get_results("SELECT DISTINCT
        $wpdb->postmeta.meta_value AS date, count(ID) as posts FROM $wpdb->posts, $wpdb->post2cat, $wpdb->postmeta WHERE $wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.post_id = $wpdb->postmeta.post_id AND $wpdb->post2cat.category_id = '$mcat' AND $wpdb->postmeta.meta_key='newsletter_month_year' AND $wpdb->posts.post_type = 'post' AND $wpdb->posts.post_status = 'publish' GROUP BY $wpdb->postmeta.meta_value ORDER BY meta_value DESC");
   
             if ( $arcresults ) {
               $afterafter = $after;
               foreach ( $arcresults as $arcresult ) {
                 $date = $arcresult->date;
                 list($month, $year) = split(' ', $date);
                 //test line - uncomment to test
                 //echo $month . " " . $year . "<br />";
                 $url = get_month_link($year,$month) . "?cat=" .$mcat;
                 $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($month), $year);
                 if ( $show_post_count )
                   $after = ' ('.$arcresult->posts.')' . $afterafter;
                 echo get_archives_link($url, $text, $format, $before, $after);
               }
             }
           }
       ```
   
 * So, when you get to the “list(split…)” line, I’ve put in a test line right after
   it that echoes out the $month and $year – just a quickie test to be sure the 
   correct output is being generated. According to the echo statement, it is – it’s
   outputting the correct $month and $year every time. However…
 * the very next line is:
 * `$url = get_month_link($year,$month) . "?cat=" .$mcat;`
 * Now, since the test echo statement says the correct info is being parsed as $
   month and $year, it stands to reason that the “$year,$month” part in the “get_month_link()”
   area would snap up these correct values – but they are not. $year comes through
   just fine, but $month is ignored for some reason. So when my links list comes
   through, it lists the year, but no month. I basically have a list of links that
   all say “2007”, and each one is linked to “domain.com/2007/00/?cat=13”.
 * Would anyone know why this is? It really doesn’t make any sense to me, since 
   it’s echoing the values correctly *just* before the get_month_link()…so I don’t
   know why it’s not coming through to the next few areas.

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 8 months ago](https://wordpress.org/support/topic/get_month_link-question/#post-621322)
 * Is the $month outputting as a number? As in 1 or 2, instead of January or February?
   Just making sure, the get_month_link function wants numbers as input.
 *  Thread Starter [Doodlebee](https://wordpress.org/support/users/doodlebee/)
 * (@doodlebee)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/get_month_link-question/#post-621333)
 * _Is the $month outputting as a number? _
 * Yeah – that was the problem! I just had someone else point that out to me, and
   I feel like an utter idiot. So no, it’s not outputting as a number.
 * Now my problem is finding a method to convert “September” to “09”….this should
   be fun 🙂
 *  Thread Starter [Doodlebee](https://wordpress.org/support/users/doodlebee/)
 * (@doodlebee)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/get_month_link-question/#post-621334)
 * got it 🙂
 *     ```
       if ( $arcresults ) {
               $afterafter = $after;
               foreach ( $arcresults as $arcresult ) {
                 $date = $arcresult->date;
                 list($month, $year) = split(' ', $date);
   
                // convert month name to number
               for($i=1;$i<=12;$i++){
                if(date("F", mktime(0, 0, 0, $i, 1, 0)) == $month){
                 $month = $i;
                }
               }
   
                 $url = get_month_link($year, $month) . "?cat=" .$mcat;
                 $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($month), $year);
                 if ( $show_post_count )
                   $after = ' ('.$arcresult->posts.')' . $afterafter;
                 echo get_archives_link($url, $text, $format, $before, $after);
               }
             }
           }
       ```
   
 *  Thread Starter [Doodlebee](https://wordpress.org/support/users/doodlebee/)
 * (@doodlebee)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/get_month_link-question/#post-621337)
 * …and even though I’ve already marked this resolved, if anyone has a little tidbit
   o’ info for me on this next question…
 * when you use the “get_month_link”, is there a way to insert text between the 
   domain name and the link? For example, the above outputs “domainname.com/2007/
   9/?cat=13”. Is it possible to change that to “domainname.com/category/2007/9”?
   Where you’ve moved the “?cat=13” to *before* the year and month, and used it’s
   nicename rather than ID?
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 8 months ago](https://wordpress.org/support/topic/get_month_link-question/#post-621340)
 * No, that’s not possible. Wouldn’t work even if it was possible. Two “nice” permalinks
   can’t intersect.
 *  Thread Starter [Doodlebee](https://wordpress.org/support/users/doodlebee/)
 * (@doodlebee)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/get_month_link-question/#post-621345)
 * aww…too bad. Well, maybe I can just figure out how to convert the ?cat=13 to 
   the nicename. The pretty permalinks thing isn’t working for that for some reason.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘get_month_link() question’ is closed to new replies.

## Tags

 * [query](https://wordpress.org/support/topic-tag/query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 2 participants
 * Last reply from: [Doodlebee](https://wordpress.org/support/users/doodlebee/)
 * Last activity: [18 years, 8 months ago](https://wordpress.org/support/topic/get_month_link-question/#post-621345)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
