[wp-hackers] Custom Post Type Archives

Erick Hitter ehitter at gmail.com
Mon Oct 24 23:07:32 UTC 2011


Daniel,

If you only want to add the rules for certain post types, you don't need to
use the *get_post_types* function. If you remove that and leave the inner
array as shown in your code, it should work.

Erick

On Sun, Oct 23, 2011 at 17:06, Aero Maxx <aero.maxx.d at gmail.com> wrote:

>  Erick,
>
> I have tried doing what you said have put in 1 of my custom post types in
> the array, and it still doesn't work when I am registering my custom post
> type myself with the register_post_type function in my themes functions.php
> file.  See here for the code I am using to setup my custom post types
> http://pastebin.com/YsHtYSiP
>
> The output from get_post_types is still an empty array, the only time the
> array returns anything is when the custom post type has been created by the
> custom-post-type-ui plugin not with the above code.
>
> Here is a copy of my code that is your code you posted earlier with the
> suggested changes to it http://pastebin.com/QBWnTa77
>
> If anyone is able to shine some light on whats going on with the code that
> registers my custom post type, I would be extremely grateful!
>
> Thank you
> Daniel.
>
> On 23/10/2011 20:32, Erick Hitter wrote:
>
> Daniel,
>
>  That is a reference to a method in the class I lifted the code from. I
> should have removed it before I put the code on PasteBin. You should replace
> that with an array of the post types you wish to add date-based archives to.
> I updated the code and added a note regarding the array for that loop.
>
>  Erick
>
> On Sun, Oct 23, 2011 at 15:23, Aero Maxx <aero.maxx.d at gmail.com> wrote:
>
>> Hi Erick,
>>
>> Thanks very much for the code, looks just what I am after as I have 8
>> custom post types, and so I have used the code as is.
>>
>> But for some odd reason I cant get my head round as to why the line with
>> "get_post_types( false )" on it doesn't return my custom post types that I
>> have registered.
>>
>> I have pasted the code for one of my custom post types here
>> http://pastebin.com/YsHtYSiP have I done something not entirely correct
>> in this code, I installed the custom-post-type-ui plugin when I create a
>> custom post type with this and choose the same options the code
>> "get_post_types( false )" does return my custom post type.
>>
>> Thank you
>> Daniel.
>>
>>
>> On 23/10/2011 16:26, Erick Hitter wrote:
>>
>>>  Daniel,
>>>
>>> WordPress doesn't, by default, support pretty permalinks for date-based
>>> post-type archives. You can append query strings to the CPT archive URL
>>> and
>>> accomplish what you're looking to do, but if you want nice permalinks,
>>> you
>>> need to manually add the rewrite rules.
>>>
>>> I added an example at http://pastebin.com/80UEbXs8 that creates the
>>> necessary rules. I pulled this from a project that had many custom post
>>> types, hence the foreach loop. As the function name implies, this code is
>>>  tied to the *generate_rewrite_rules* action. Also, to avoid conflicts
>>> with
>>> post names, etc., the URLs include a *date* slug between the post type
>>> slug
>>>
>>> and the date pieces of the URL. This may or may not be needed for your
>>> project, and removing line 14 from the example will eliminate the
>>>  *date* element
>>>
>>> from the URLs if you don't want/need it.
>>>
>>> Erick
>>>
>>> On Sat, Oct 22, 2011 at 18:21, Aero Maxx<aero.maxx.d at gmail.com>  wrote:
>>>
>>>   Hello,
>>>>
>>>> Could someone point me in the right direction in how to make
>>>> day/month/year
>>>> archives for custom post types.
>>>>
>>>>  Normal blog posts get there archives like
>>>> http://www.domain.co.uk/2010/**
>>>> 12<http://www.domain.co.uk/2010/12>  but can I do something similar for
>>>>
>>>>
>>>> custom post types, I was thinking/hoping something like this would work
>>>>  http://www.domain.co.uk/lotto/**2010/12<
>>>> http://www.domain.co.uk/lotto/2010/12>or
>>>> http://www.domain.co.uk/lotto/**2010<http://www.domain.co.uk/lotto/2010>but
>>>> these do not work.
>>>>
>>>>
>>>> I have has_archive set to true, and this does load the
>>>> archive-{post-type}.php file, but I cant get the year/month/day archive
>>>> to
>>>> work, it just seems to load this page as is, and doesn't seem to know
>>>> its an
>>>> archive page.
>>>>
>>>> Thank you.
>>>> Daniel.
>>>>  ______________________________**_________________
>>>> wp-hackers mailing list
>>>> wp-hackers at lists.automattic.**com<wp-hackers at lists.automattic.com>
>>>> http://lists.automattic.com/**mailman/listinfo/wp-hackers<
>>>> 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