WordPress.org

Ready to get started?Download WordPress

Forums

CPT-onomies: Using Custom Post Types as Taxonomies
[resolved] Term excerpt/description? (7 posts)

  1. ncfrank
    Member
    Posted 1 year ago #

    Wonderful plugin. It's super awesome!

    I'm sure I'm missing something simple here, but from looking around I haven't seen an answer. Apologies if I missed it in the documentation.

    Ultimately I'm looking to have:
    1. An archives page that shows all the different kinds of agencies(that also shows their excerpt/description) (this piece already works with excerpts.)
    2. When you click on an agency entry and goto a specific agency CPT-onomy term
    I'd like to show that excerpt/description at the top of the page above the list of posts (defined as a different CPT-onomy: "Projects")they are related to to provide context to the reader.

    Some things I'm trying:

    In the tags and categories taxonomies there's a description field, and it's even seen if you var_dump;

    $agencies = wp_get_object_terms( $post->ID, "agencies" );
    if ( $agencies && !is_wp_error( $agencies ) ) {
       foreach ( $agencies as $agency ) {
          $line = $agency->name;
    
    	   var_dump($cpt_onomy->get_term($agency, "agencies"));
    	   var_dump($agency);
    	   var_dump(term_description( $agency, "agencies" ));
    	  echo $line;
       }
    }

    They all come back with a description field that is empty:

    ["description"]=>
      string(0) ""

    It makes sense as I don't see a description field when I create a new agency entry, but there is a field returning, perhaps there's a way to add a field to enter that data on the term entry page(add new agency)?
    Perhaps this is apart of:
    http://rachelcarden.com/cpt-onomies/documentation/term_description/
    not working with wordpress "right now"

    I noticed in the cpt-onomy.php (function convert_object_to_cpt_onomy_term) has:

    $term = array(
    					'term_id' => $term->ID,
    					'name' => apply_filters( 'the_title', $term->post_title, $term->ID ),
    					'slug' => $term->post_name,
    					'term_group' => $term->post_parent,
    					'term_taxonomy_id' => 0,
    					'taxonomy' => $term->post_type,
    					'description' => '',
    					'parent' => $term->post_parent
    				);

    which seems to show that the description is being set to empty.

    I have enabled custom fields, and tried to enter a description there, I'm sure there's more I'd need to do to access that info (any thoughts here?)

    I've set up my CPT-onomy to have excerpts, and have populated them, perhaps I could use those?

    Thanks for any of your time for your thoughts/links to more reading.

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

  2. Rachel Carden
    Member
    Plugin Author

    Posted 1 year ago #

    Hi! First off, I'm glad you like the plugin! It is a labor of love!

    Second, at this time term descriptions don't work with CPT-onomies because CPT-onomy information is stored differently than regular taxonomy information so there's no set place to store a defined "cpt-onomy term description" at this point in time.

    That being said, the custom post does have its "post_content" and "excerpt" fields, as well as custom fields to fulfill any "description" needs.

    If you're fine with using the "excerpt", you could add the following code inside your foreach loop:

    echo apply_filters( 'the_excerpt', get_post( $agency->term_id )->post_excerpt );

    Or you could setup a custom field for your description and retrieve the info with the following code inside your loop. For this example, the custom field key will be 'description':

    get_post_meta( $agency->term_id, 'description', true );

    Hope this helps!

  3. gandalf147
    Member
    Posted 1 year ago #

    hi, i have the same problem.
    i've tried this code:

    <?php
    $terms = get_the_terms( $post->ID, 'negozi' );
    if ( $terms && ! is_wp_error( $terms ) ) {
       $negozi = array();
       foreach ( $terms as $term ) {
        $negozi[] = $term->name;
    echo apply_filters( 'the_excerpt', get_post( $negozi->term_id )->post_excerpt );
       }
       $negozi = join( ", ", $negozi );
    }
    ?>

    but seems doens't print the excerpt

    thanks in advance

  4. gandalf147
    Member
    Posted 1 year ago #

    solved with this code

    <?php
    $negozi = wp_get_object_terms( $post->ID, 'negozi' );
    $negozi = get_the_terms( $post->ID, 'negozi' );
    foreach ( $negozi as $negozi ) {
    echo apply_filters( 'the_excerpt', get_post( $negozi->term_id )->post_excerpt );
    }
    ?>

    thanks

  5. Rachel Carden
    Member
    Plugin Author

    Posted 1 year ago #

    Awesome! Glad you solved it!

  6. gandalf147
    Member
    Posted 1 year ago #

    thanks Rachel.
    since you're so kind, i would like to ask you if there is a better way to have the number of CPT in taxonomy than this

    $negozi = wp_get_object_terms( $post->ID, 'negozi' );
    $negozi = get_the_terms( $post->ID, 'negozi' );
    $nome_negozio = apply_filters( 'the_slug', get_post( $negozi->term_id )->post_name );
    $query = new WP_Query( array( 'negozi' => $nome_negozio ) );
    $num_coupon = $query->found_posts;
    echo $num_coupon;
    wp_reset_query();

  7. Rachel Carden
    Member
    Plugin Author

    Posted 1 year ago #

    Both wp_get_object_terms() and get_the_terms() should include a 'count' in the term object, e.g. $negozi->count.

    Give that a shot.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.