Warning: getimagesize(): SSL operation failed with code 1. OpenSSL Error messages: error:0A000086:SSL routines::certificate verify failed in /var/www/vhosts/spacedonkey.de/httpdocs/wp-content/plugins/print-pro-matic/print-pro-matic.php on line 261

Warning: getimagesize(): Failed to enable crypto in /var/www/vhosts/spacedonkey.de/httpdocs/wp-content/plugins/print-pro-matic/print-pro-matic.php on line 261

Warning: getimagesize(https://spacedonkey.de/wp-content/uploads/2021/10/printer-24.png): Failed to open stream: operation failed in /var/www/vhosts/spacedonkey.de/httpdocs/wp-content/plugins/print-pro-matic/print-pro-matic.php on line 261

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" /]