• Resolved David Gard

    (@duck_boy)


    Hey all,

    I am trying to display archived posts from across 2 custom post types but I cannot get it to work.

    To display the archive by month I use –

    /** Custom function to alter the WHERE protion of the wp_get_archives() query */
    add_filter('getarchives_where', array($this, 'getarchives_filter'));
    function getarchives_filter($where){
    	$where = "WHERE post_type='".POST_TYPE_NEWS."' OR post_type='".POST_TYPE_TLA."' AND post_status = 'publish'";
    	return $where;
    }
    $args = array(
    	'type' => $type,
    	'format' => 'custom',
    	'before' => '<li class="link_arrow">',
    	'after' => '</li>',
    	'limit' => $limit,
    	'show_post_count' => true
    );
    wp_get_archives($args);

    This displays the link just fine and creates links in this format –
    https://www.mydomain.com/2011/01

    But when I click the link the query that is run searchs for the Post Type post, which doesn’t exist on my site. Because of this the query returns true for is_404(), meaning that I am taken to my ‘404.php’ page as opposed to the ‘archive.php’ page.

    I’ve tried using the posts_where filter and the pre_get_posts filter, but neither seem to work. Does anybody know what I need to do to make this right?

    Thanks.

Viewing 1 replies (of 1 total)
  • Thread Starter David Gard

    (@duck_boy)

    Ok, so no luck finding a proper solution, so I resorted to a hack –

    added the following on line 2337 of wp-includes/query.php

    if(is_archive()){
    	$post_type = array(
    		POST_TYPE_NEWS,
    		POST_TYPE_TLA
    	);
    }

    If anyone ever does come up with a proper solution for this I’d love to know it. Basically I needed the hack because my archive.php file was being ignored so any filters or custom queries that I placed in there were also being ignored and I was being taken straight to the 404 page.

Viewing 1 replies (of 1 total)
  • The topic ‘Archived custom post type posts’ is closed to new replies.