Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #515533

    Hi,

    On the site I am working on each Portfolio item can be in multiple categories so I would like to list the categories on the single-portfolio page. I read a bunch of posts and followed the code in the one that came the closest, but still no luck, I’m getting an empty array.
    I added the following code in my child theme to loop-portfolio-single.php. To test it, I have echoed the post id and category array to the screen. The post id is correct, but the category array is empty.I have tried both portfolio-entries and portfolio-categories as the taxonomy. I would appreciate any advice you could give me.

    echo $post_id; // test
    $terms = get_the_terms($post_id, 'portfolio-entries');
    print_r ($terms); // test
    if ( $terms && ! is_wp_error( $terms ) ) {
    echo "sparky"; // test
    $terms_mediums = array();
    	foreach ( $terms as $term ) {
    	$newterms[$term->slug] = $term;
    	}
    	 ksort($newterms);
    	foreach ( $newterms as $term ) {
    		$terms_mediums[] = $term->name;
    	}
    						
    $terms_list = join( ", ", $terms_mediums );
    echo $terms_list;
    unset($newterms); 
    }
     else { echo "nosparky"; // test }
    echo '</div>';

    Result:

    571WP_Error Object ( [errors] => Array ( [invalid_taxonomy] => Array ( [0] => Invalid taxonomy ) ) [error_data] => Array ( ) ) nosparky
    
    #516250

    Hey kallym!

    Thank you for using Enfold.

    It should be “portfolio_entries”, not “portfolio-entries”.

    Cheers!
    Ismael

    #516723

    That worked! Thank you!!.

    #517172

    Hi,

    Great, glad we could help :-)

    Regards,
    Rikard

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Problem with listing portfolio categories on single post’ is closed to new replies.