• Resolved pcmdv

    (@pcmdv)


    Hi Guys,
    I would like to return a custom Term Field for a given taxonomy when on a Post Single page.

    eg. “Card A” Single page displaying all my custom post fields about that card. Card is in a taxonomy “Collection” > “Collection A”

    Each Collection has custom Term fields (blurb, image, link) which I would like to display on my Single post page at the bottom.

    if (have_posts()) { $count = 0;
    		while (have_posts()) { the_post(); $count++;
    
    echo types_render_field("card-number", array("show_name"=>"false","output"=>"html","id"=>"$card-number"));
    echo '<h1>'. get_the_title() .'</h1>';
    echo types_render_field("card-image", array("show_name"=>"false","output"=>"html","id"=>"$card-image","size"=>"large"));
    echo ''. the_content() .'';
    
    echo types_render_field("card-source", array("show_name"=>"false","output"=>"html","id"=>"$card-source","size"=>"large"));
    
    echo wp_strip_all_tags( get_the_term_list(get_the_ID(), 'source-archive', '', ' / ') );
    echo types_render_termmeta("archive-blurb", array("term_id"=>"get_the_ID()","show_name"=>"false","output"=>"html","id"=>"$archive-blurb" ));
    echo types_render_termmeta("archive-logo", array("term_id"=>"get_the_ID()","show_name"=>"false","output"=>"html","id"=>"$archive-logo","size"=>"large" ));
    echo types_render_termmeta("archive-link", array("show_name"=>"false","output"=>"raw","id"=>"$archive-link"));
    
    		}
    	}

    types_render_termmeta don’t display anything and I think it’s because it needs to know that ID of the taxonomy that the post is marked in.

    I hope that makes sense. Any ideas what I should change?

    Thanks

    https://wordpress.org/plugins/types/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Beda

    (@bedas)

    Custom Fields for Taxonomies can only be used on Taxonomy Archives and Taxonomy Views

    However you can use the Types API and force the Term ID:
    https://wp-types.com/documentation/user-guides/displaying-wordpress-term-fields/

    Example:
    echo types_render_termmeta("cat-featured-image", array( "term_id" => "5", "alt" => "Category Featured Image", "width" => "300", "height" => "200" ) );

    cat-featured-image in above example is the Term Field slug and 5 the Term ID.

    Thread Starter pcmdv

    (@pcmdv)

    Ah thanks, thats great and has sorted my problem.

    I had to go into PHPmyAdmin to find the term id in wp_termmeta. I couldn’t seem to find the term id from within the dashboard like you can for posts etc when you hover over them.

    Thanks!

    Plugin Support Beda

    (@bedas)

    You can find the ID when you click on edit (for the term) in the URL.

    I will mark this thread as resolved.

    Thank you

    Thread Starter pcmdv

    (@pcmdv)

    Just to follow up – I initially thought it was more fixed then it was.

    I ended up with this to dynamically get the term id based on which taxonomy the post was assigned to:

    // get the id of the post
    $the_id = get_the_ID();
    
    // get the custom taxonomy term name
    $source_archive_name = wp_strip_all_tags( get_the_term_list( $the_id, 'source-archive', '', ' / ' ) );
    
    // read all the data for the term into an array
    $term_data = get_term_by( 'name', $source_archive_name, 'source-archive', ARRAY_A );
    
    // pull the term id out of the array
    $the_term_id = $term_data["term_id"];
    
    echo wp_strip_all_tags( get_the_term_list(get_the_ID(), 'source-archive', '', ' / ') );
    echo types_render_termmeta("archive-blurb", array("term_id" => $the_term_id,"show_name"=>"false","output"=>"normal","id"=>"$archive-blurb"));
    echo types_render_termmeta("archive-logo", array("term_id" => $the_term_id,"show_name"=>"false","output"=>"html","id"=>"$archive-logo","size"=>"large" ));
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘types_render_termmeta on a Post Page with a given taxonomy’ is closed to new replies.