Skip Navigation

Resolved

Reported for: WPML Multilingual CMS 3.3.6

Resolved in: 3.3.7

Overview of the issue

Using wp_get_archives and specifying the argument post_type in order to filter the display of posts for the archive page of a given custom post type, is not working.

Please note that this issue was introduced with the WordPress 4.4 release.

Example:
Have a custom post type with slug “news”, and create a custom archive template for that custom post type in a theme (archive-news.php).
In that file you can use the following code to render the archive:

$my_archives=wp_get_archives(array(
	'type'=>'alpha', 
	'show_post_count'=>true, 
	'limit'=>20, 
	'post_type'=>'news', 
	'format'=>'html' 
));
print_r($my_archives);

Currently, this code will not work and no posts will be displayed.

Workaround

Before taking any of the following steps, please make sure you understand that you are editing the files in your site and that this, if not properly done, may cause your website to stop functioning.

It is strongly recommended that you try this in a safe environment first, or at least that you run a full backup of your website before proceeding.

  1. Open the sile sitepress-multilingual-cmssitepress.class.php
  2. Go to a row 219
    • Replace:
      add_filter( 'getarchives_join', array( $this, 'getarchives_join' ) );
    • With:
      add_filter( 'getarchives_join', array( $this, 'getarchives_join' ), 10, 2 );
  3. Go to a row 3685
    • Replace:
      function getarchives_join( $join ) {
      	return $join . " JOIN {$this->wpdb->prefix}icl_translations t ON t.element_id = {$this->wpdb->posts}.ID AND t.element_type='post_post'";
      }
    • With:
      function getarchives_join( $join, $args ) {
      	$post_type = array_key_exists( 'post_type', $args ) ? $args['post_type'] : 'post';
      	$post_type = esc_sql( $post_type );
      
      	return $join . " JOIN {$this->wpdb->prefix}icl_translations t ON t.element_id = {$this->wpdb->posts}.ID AND t.element_type='post_" . $post_type . "'";
      }