[wp-hackers] Custom post types and wp_get_archives

Aero Maxx aero.maxx.d at gmail.com
Tue Jul 3 18:08:28 UTC 2012


Thats ok no worries....

Thats great it works really well and just what I was after, although now 
I realise that the archive list is incredibly long, and something that I 
never considered, and there is no way to limit it on the widget side bar.

But I have something to be getting along with til I find a better 
solution, so thank you very much!

On 03/07/2012 18:19, Lionel Pointet wrote:
> Oh right! I misunderstood your request, sorry...
>
> So, the first thing I notice in the 'wp_get_archives' function is that 
> the post_type is hardcoded in the where clause.
> But you can easily filter it to add your CPT slug thanks to the 
> 'getarchives_where' filter:
>
>     function example_getarchives_where($where) {
>         return str_replace("WHERE post_type = 'post'", "WHERE
>     post_type IN ('post', 'cpt')", $where);
>     }
>     add_filter('getarchives_where', 'example_getarchives_where');
>
> There may be another better solution, but that's the first thing I 
> found and I know it'll work...
>
> Lionel
>
> Le 03/07/2012 18:26, Aero Maxx a écrit :
>> Hi Lionel, All,
>>
>> I have created the custom post type and its all working and so on, 
>> but I would like people to be able to view an archive list of the 
>> last month and so on, just like they can with my normal blog posts.
>>
>> The archive themselves do work, but I have no way for my visitors to 
>> find them ? Because am unsure how to get them into the archives list 
>> on the sidebar, this is what I require help with.
>>
>> For example my blog posts archive shows as :-
>>
>> July 2012
>> June 2012
>> ...
>> January 2012
>>
>> but clicking on those links it shows only the blog post archives, I 
>> would either like to get my custom post types to affect that list, 
>> i.e. if there are no blog posts for say December 2011, but there are 
>> custom post types for this month, I would like there to be a link for 
>> it, but it seems this is not possible as wp_get_archives doesn't 
>> support the post-type parameter.
>>
>> So I am wondering how I would be able to do a list similar to the 
>> blog posts one that would display months, years archive links for my 
>> custom post types.
>>
>> On 03/07/2012 16:25, Lionel Pointet wrote:
>>> Hi Daniel,
>>>
>>> You can read this codex page : 
>>> http://codex.wordpress.org/Function_Reference/register_post_type
>>> And specifically the 'has_archive' arg that allows you to get your 
>>> post type archived as the others (posts or pages) and allows you to 
>>> override the default slug ($post_type by default) too.
>>>
>>> I hope that's what you wanted...
>>> Lionel
>>>
>>> Le 03/07/2012 17:23, Aero Maxx a écrit :
>>>> Hi All,
>>>>
>>>> Is there a simple way to get custom post types to appear in the 
>>>> archive along with the normal blog posts when using the 
>>>> wp_get_archives function, if not is there a similar function that 
>>>> can be used to display a list for the custom post types the same 
>>>> way it does for normal blog posts ?
>>>>
>>>> I would prefer not to use a plugin, but if this is the only way 
>>>> then I guess I would do so, I just thought there maybe something 
>>>> built into wordpress that would do this seeing as the custom post 
>>>> types are there, and that maybe someone has thought users may want 
>>>> this.
>>>>
>>>> I have googled and looked in the codex but not been able to find 
>>>> what I was looking for function wise as to what I was trying to 
>>>> achieve.
>>>>
>>>> Thanks in advance
>>>> Daniel.
>>>> _______________________________________________
>>>> wp-hackers mailing list
>>>> wp-hackers at lists.automattic.com
>>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>
>>>
>>> _______________________________________________
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.com
>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>>
>
>




More information about the wp-hackers mailing list