Ready to get started?Download WordPress


CPT-onomies: Using Custom Post Types as Taxonomies
[resolved] display the field of posttype/taxonomy on frontend (6 posts)

  1. neha
    Posted 3 months ago #

    i have a posttype called store with fields "title" and "genre".

    i ahve thisposttype store set a CPTnomies to posttype called books as checklist which lists the store titles as checkbox

    now i am trying to display on the front end the store selected and based on the selection the corresponding genre too.

    i am unable to get that when i use <?php echo get_terms('genre');?> it gives me error....how do i get the desired output.



  2. neha
    Posted 3 months ago #

    instead of custom field how can get the post's permalink to be displayed for the selected store title...i have tried everything nothing seemss to work

  3. Rachel Carden
    Plugin Author

    Posted 3 months ago #

    Well, get_terms( 'genre' ) doesn't work because 'genre' is a custom field and not a taxonomy or CPT-onomy.

    As for the permalink, you have to get the selected store's ID using wp_get_object_terms() and then use get_permalink():

    // $post_id is the post ID of the current book
    // I don't know the context of your code so you may
    // have to replace this with your own info.
    $stores = wp_get_object_terms( $post_id, 'actors' );
    // $stores will contain arrays of info for each store
    // that is assigned to the book, including the store's
    // term_id which is the same as the store's post ID.
    if ( $stores && !is_wp_error( $stores ) ) {
       echo '<ul>';
       foreach ( $stores as $store ) {
          echo '<li><a href="' . get_permalink( $store->term_id ) . '">' . $store->name . '</a></li>';
       echo '</ul>';

    I hope this helps!

  4. neha
    Posted 3 months ago #

    is there any way to get the custom field in the posttype to be echoed after its converted to cpt-onomy?

    p.s-thanx so much replying :)

  5. neha
    Posted 3 months ago #

    racehl with the code u gave ...it pulls in the permalink of the current as well as the previous post from the CPT...is it pulling 2 of them

  6. neha
    Posted 3 months ago #

    also it pulla in the permalink of the post and not the cpt


You must log in to post.

About this Plugin

About this Topic


No tags yet.