WordPress.org

Ready to get started?Download WordPress

Forums

CPT-onomies: Using Custom Post Types as Taxonomies
[resolved] CPT archives and terms (6 posts)

  1. r1987
    Member
    Posted 2 years ago #

    First, a big thanks and a thousand hugs, Rachel, for creating this plugin!

    But I have ended up at a problem, that I can't understand.

    I have 9 different custom post types (actors, productions, theatres, dancers etc.). On single page view the CPT-onomies work like charm.

    But when I create a archive-actors.php page and want to show 10 posts from actors with their attached terms, wordpress will only show terms for the first post, everything else is empty. This only occurs when i want to show more than 1 post on archive page.

    I'm using get_the_term_list to output CPT-onomies's.

    http://wordpress.org/extend/plugins/cpt-onomies/

  2. Rachel Carden
    Member
    Plugin Author

    Posted 2 years ago #

    Hey! Thanks for the hugs =)

    Can you send me your archive-actors.php file? Contact me and I'll respond pretty quickly so you can attach the file.

  3. Rachel Carden
    Member
    Plugin Author

    Posted 2 years ago #

    Thanks for the email and the code!

    I used your code on my test site and saw that it was doing the same for me. It was only showing the terms for the first post.

    After a little digging, I discovered it was a caching problem so I flushed my cache. I just placed the following code at the top of my archive-actors.php file:

    wp_cache_flush();

    That fixed the problem for me, just be sure to remove the function after you've run the page. The function only needs to be run once.

    Oh, and FYI: using the WP function get_the_term_list() does work BUT where its supposed to link to the term's archive page, it links to the custom post type's single post page because of some conflicts with taxonomy and custom post type rewrites.

    If you prefer the single post link, then ignore this part. But if you would prefer the link to the term's archive page, you can use the CPT-onomy get_term_link(). All you have to do is add '$cpt_onomy->' to the front of the function:

    <p><?php echo $cpt_onomy->get_the_term_list( $post->ID, 'directors', '<h6>Directors:</h6> ', ', ', '' ); ?></p>
    
    <p><?php echo $cpt_onomy->get_the_term_list( $post->ID, 'events', '<h6>Events:</h6> ', ', ', '' ); ?></p>
    
    <p><?php echo $cpt_onomy->get_the_term_list( $post->ID, 'productions', '<h6>Artists:</h6> ', ', ', '' ); ?></p>
  4. r1987
    Member
    Posted 2 years ago #

    Well the wp_cache_flush(); does the job ! But when I remove it, then everything goes back like I started. Is it a big problem, when I leave the function wp_cache_flush(); on top of page? Will it cause some problems in the future?

  5. Rachel Carden
    Member
    Plugin Author

    Posted 2 years ago #

    Well, crap. I apologize. I didn't remove it either after I was done testing and it, too, put me back at the beginning.

    Let me dig around some more...

  6. Rachel Carden
    Member
    Plugin Author

    Posted 2 years ago #

    Ok. I think I found the problem. It will be fixed in the next update but I went ahead and emailed you the new code.

    The problem lied in wp_get_object_terms() having an issue with multiple object IDs.

    If anyone else stumbles upon this problem before version 1.0.3, look for the following code in the wp_get_object_terms() function in the cpt_onomy.php file:

    // this allows for a string with one object id or an array with multiple object ids
    if ( !is_array($object_ids) )
       $object_ids = array($object_ids);
    $object_ids = array_map('intval', $object_ids);

    and replace it with:

    // this allows for a string with one object id or an array with multiple object ids
    if ( !is_array( $object_ids ) ) {
       $object_ids = str_replace( ', ', ',', $object_ids );
       $object_ids = explode( ',', $object_ids );
    }
    $object_ids = array_map( 'intval', $object_ids );

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic