• Resolved David Keevis

    (@upstaterider)


    I’m working on building out my CPT archives. I have a CPT named ‘Sermon’ with an associated taxonomy named ‘Sermon-Category’ created with ACF. I have multiple hierarchal terms associated with the tax. I added a Description to the tax and the terms. I can pull the description of each term with ease using a GB dynamic content block.

    I have not been able to retrieve the tax description field.

    I’ll be using this data in the archive as introduction info for what the posts in the archive are about.

    My intent is to use a single archive for multiple different CPT’s, each with a custom tax. Only one CPT type will be fetched in the archive with a faceted search capability (WP Grid Builder). I would like to pull the tax description based upon which CPT is selected.

    Would really appreciate an approach to this use case and am grateful for assistance provided.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter David Keevis

    (@upstaterider)

    Finally got a shortcode working that does part of what I’d like.

    add_shortcode( 'tax_description', function() {
     ob_start(); 
    $taxonomy = 'your-custom-tax'; // Replace 'your-custom-tax' with the actual taxonomy slug 
    
    // Get the taxonomy object 
    $taxonomy_object = get_taxonomy($taxonomy); 
    
    // Get the taxonomy description 
    $taxonomy_description = $taxonomy_object->description;
    
     // Output the taxonomy description echo $taxonomy_description; 
    return ob_get_clean();
    } );

    What I’d like to do is dynamically fetch & pass the argument ‘your-custom-tax’ from the taxonomy of the current archive being displayed.

    Thanks so much.

    Moderator bcworkz

    (@bcworkz)

    Your shortcode snippet needs an echo statement like echo $taxonomy_description;. While output buffering is acceptable, it’s preferred that output be collected in a normal variable and you’d then return that variable in the end. You could get rid of the buffer statements and do return $taxonomy_description; instead of echoing.

    dynamically fetch & pass the argument ‘your-custom-tax’

    I’m not clear on exactly what you want to do here. Which argument are you fetching? The archive page’s taxonomy term? You can get it with get_queried_object(). For a tax term archive query this will return a WP_Term object. You could then concatenate whichever properties you like to the shortcode’s overall variable containing its output.

    Thread Starter David Keevis

    (@upstaterider)

    Thanks. I went with the return variable. And worked with the WP_Term object, extracting the tax description from it. Got exactly what I needed and appreciate you getting me pointed in the right direction.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Retrieve Custom Taxonomy Description’ is closed to new replies.