2

Permalinks are (finally) working for individual posts of the custom yoga-event type I've created.

And archive works without URL rewriting:

http://website.localhost/?post_type=yoga-event

However get_post_type_archive_link( 'yoga-event' ) returns false.

This is the array I'm sending to register_post_type:

Array
(
        [labels] => Array
                (
                        [name] => Yoga Events
                        [singular_name] => Yoga Event
                        [menu_name] => Yoga Events
                        [all_items] => Yoga Events
                        [add_new] => Add New
                        [add_new_item] => Add New Yoga Event
                        [edit_item] => Edit Yoga Event
                        [new_item] => New Yoga Event
                        [view_item] => View Yoga Event
                        [search_items] => Search Yoga Events
                        [not_found] => No Yoga Events found
                        [not_found_in_trash] => No Yoga Events found in Trash
                        [parent_item_colon] => Parent Yoga Event:
                )

        [public] => 1
        [rewrite] => Array
                (
                        [slug] => yoga-event
                )

        [has_arhchive] => 1
        [menu_icon] => dashicons-book-alt
)

I can sort of make my own "archive" like this:

$type = 'yoga-event';
$args=array(
    'post_type' => $type,
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'ignore_sticky_posts'=> 1);

$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : 
    $my_query->the_post(); 
    ?>

        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?> </a></p>

    <?php

    endwhile;
} // list of yoga-event items

But I'm guessing that the array that register_post_type is getting has some kind of misconfiguration.

Any insights?

PS:

//List Post Types
foreach ( get_post_types( '', 'names' ) as $post_type ) {
     echo '<p>' . $post_type . '</p>';
}

Returns yoga-event (among others).

2
  • 4
    there's a typo here- has_arhchive, is that also in your code?
    – Milo
    Commented Mar 12, 2016 at 7:07
  • good eyes, man. that was the problem (at the end of a long line of others). Want to post answer?
    – MikeiLL
    Commented Mar 12, 2016 at 14:16

2 Answers 2

1

Can I see your register_post_type line? Those are usually like: register_post_type( 'some-post-type', $args );.

In this example, some-post-type would be the ID that you use in get_post_type_archive_link( 'some-post-type' ), not the rewrite slug yoga-event.

1
  • no. i should probably have specified the first argument, but it matched the post returned by get_post_types
    – MikeiLL
    Commented Mar 12, 2016 at 14:17
0

There was a typo in the code above, which one of the community pointed out, but I'll add here that that final piece of the puzzle for me was this little bit of code (also SO-based) by which we can examine a CPT as WP understands (outputs) it:

$type = 'yoga-event';
//let's look at our CPT:    
$type_obj = get_post_type_object($type);
mz_pr($type_obj);

function mz_pr($message) {
    echo "<pre>";
    print_r($message);
    echo "</pre>";

Also this wonderful CPT Class is being a great way to generate the CPT. (Note, though that I am currently adding 'has_archive' => True`` to theregister_post_types` array manually, as the method for adding it via an "instance method" didn't seem to be working.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.