Support

Account

Forum Replies Created

  • @hube2
    Thanks for the guidance so far. I’ve managed to solve all my problems, including the term returning concern; just one little obstacle left; might be more php/html related.

    I manage to return the custom field taxonomy terms:

    <?php 
    $queried_object = get_queried_object(); 
    $taxonomy = $queried_object->taxonomy;
    $term_id = $queried_object->term_id;
    
    $terms = get_field( 'custom_field', $taxonomy.'_'.$term_id);
    
    foreach( $terms as $term ):?>
    <a href="<?php echo get_term_link( $term );?>"> <?php echo $term->name; ?> </a>
    <?php endforeach; 
    ?>

    This does a good job of returning and listing the terms. It lists them down the page (separate lines). I need to list the terms separated by commas (on the same line). There are a few loop suggestions on the net about listing array entries separated by commas including the implode() function. Its proving to be a lil’ tricky incorporating a loop or the implode() function within this foreach() loop and achieving the desired output. It seems the foreach() function is forcing the values out on separate lines? Further more what about listing the terms in order of child first and parent last?

    Would appreciate your directions/suggestions.

  • My main focus has been on
    displaying a taxonomy field that is an object on a taxonomy archive page

    . I keep getting the error message:

    “WP_Term could not be converted to string”

    I’m missing something…

    Note: When taxonomy field is set to return term ID, no error message; ID is successfully returned.

    I did not find any documentation on your site on returning/displaying an object from a taxonomy custom field.

  • I guess this is where printf() and sprintf() come into play right? Because the_field() alone doesn’t help with all desired output display formats.

  • @hube2: I’m able to now retrieve an array with:

    <?php
    $queried_object = get_queried_object();
    $taxonomy = $queried_object->taxonomy;
    $term_id = $queried_object->term_id;
    
    $value = get_field( 'test_field', $taxonomy.'_'.$term_id);
    if( $value ) {
        echo $value;
    } else {
        echo 'empty';
    }
    ?>

    Why cant the_field() do what echo does here?

    I retrieve an array when the custom field is text & get an error message when its a taxonomy term:

    “Catchable fatal error: Object of class WP_Term could not be converted to string”

    I also retrieve an array when the custom field is an image.

    Looks like we now have to iterate through the string array in order to show the value; brings back the 2nd aspect of my question.

    How do you best display the returned string(s)/array on a taxonomy term archive page:
    -if ACF field value is text?
    -if ACF field value is an image?
    -if ACF field value is a single or multiple taxonomy terms?
    -if I would like to display the term values as linkable vs non linkable?

  • @hube2: Hello John, Thanks for taking a look

    As titled ‘Returning Custom Field Values on Term archive pages’… I decided to troubleshoot why no values were been returned/displayed; I enabled the custom field for post types as well.

    How do I get custom field values to be displayed on term archive pages?

    Hence the objective here is custom field ‘test_field‘ was created with a term location. I later also included locations: post type post & post type custom post‘ as a means of testing.

    Results seem to be returned ok for post types.

    Hence the questions were:

    1 – How do I get custom field values to be displayed on term archive pages? This is my main problem.
    2 – Suggestions on the best way to return/display values that are taxonomy terms (array); avoiding errors like “Catchable fatal error: Object of class WP_Term could not be converted to string“?
    3 – How can you return these terms if it was a single term vs. multiple and if needed as linkable or non linkable string returned?


    @hube2
    : Hope I have addressed your confusion.

Viewing 7 posts - 1 through 7 (of 7 total)