Archive-Pro-Matic Pretty URL Rewrite

The goal is to change an ugly archive url into a pretty url. For example here is a quarterly custom post type archive:

    The links are in a format of:

    https://spacedonkey.de/date/2012/?q=4&post_type=monkey

    And they would look better with something like:

    https://spacedonkey.de/monkey/2012/Q4

    To accomplish this, first the Add rewrite rules must be checked on the Archive-Pro-Matic settings page:

    After the CPT Rewrite Rules has been checked and saved. It might be necessary to flush the rewrite rules by simply navigating to:
    Dashboard > Settings > Permalinks – do nothing, and re-save the permalink settings.

    Second a custom url rewrite function must be added to the child-theme’s function.php file. This function uses a new filter that has been added to manually overwrite the url that archive-pro-matic uses:

    add_filter('apm_archive_link', 'pretty_my_archive_url');
    function pretty_my_archive_url($url){
        $url_args = explode('?', $url);
        if(!empty($url_args[1])){
           parse_str($url_args[1], $args);
           if(!empty($args['year']) && !empty($args['q'])){
              $url = $url_args[0].$args['year'].'/Q'.$args['q'].'/';
           }
        }
        return $url;
    }

    Now, when we display a quarterly archive for a custom post type, the urls are prettier:

    [archives type="quarterly" post_type="donkey" /]

      And here is a test of just using the standard yearly archive for a custom post type:

      [archives post_type="donkey" /]

      Archive Pro Matic Exclude Single Cat

      Test to see if a single category can be excluded from an archive list.

      [archives type="monthly" cat_id="-51"/]

      Archive-Pro-Matic Monthly Sub Post-By-Post

      This is a test of a monthly archive that displays a sub-list of post-by-post archives.

      [archives type="postbypost" sub_options="true" limit="10"/]

      Categories

      Here are examples of limiting by category. First, using cat_id

      [archives type="postbypost" sub_options="true" cat_id="55" limit="10"/]

      Taxonomies

      Next, Using taxonomy and term. This pair can be used for any taxonomy, including category:

      [archives type="postbypost" sub_options="true" taxonomy="category" term="archive-pro-matic" limit="10"/]