• Resolved helenagwyn

    (@helenagwyn)


    When showing a (taxonomy) archive-page, the current pod in a pods-block is the first (custom) post on the page.

    I have a related custom taxonomy attached to it with a few extra fields, but they can’t be used in a template within this pods-block.

    Is this a bug or part of how wordpress works?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Paul Clark

    (@pdclark)

    Hi @helenagwyn,

    If I’m understanding the problem correctly, it sounds like you’re trying to use a Pods block on a taxonomy archive page, where the post type being displayed also is related to another taxonomy which contains some additional fields.

    To do that, you must be using Full Site Editing with a block-based theme. That should work fine.

    Below is an example adding the Pods Single Item block to the All Archives template of Twenty Twenty-Three. In this example, the archive being viewed is /category/uncategorized (posts), the custom taxonomy is custom_taxonomy, which has been connected to posts with both the Connections tab and a relationship field called relationship_field_to_custom_taxonomy. custom_taxonomy has a field called some_field.

    This is the content of the template of the Pods Single Item block, which has been set to Pod Name: - Use Current Pod -:

    <p>Current Post: {@post_title}</p>
    
    <p><strong>Terms assigned via Connection:</strong> {@custom_taxonomy}</p>
    <p><strong>Terms assigned via relationship field:</strong> {@relationship_field_to_custom_taxonomy}</p>
    <p>
    <strong>Iteration over Taxonomy Connection:</strong> 
    [each custom_taxonomy]
    	<a href="{@permalink}">{@name}</a>: {@some_field}<br/>
    [/each]
    </p>
    <strong>Iteration over Taxonomy Field:</strong> 
    [each relationship_field_to_custom_taxonomy]
    	<a href="{@permalink}">{@name}</a>: {@some_field}<br/>
    [/each]
    </p>

    Which outputs:

    Current Post: Hello world!

    Terms assigned via Connection: Custom Taxonomy Term A and Custom Taxonomy Term B

    Terms assigned via relationship field: Custom Taxonomy Term A and Custom Taxonomy Term B

    Iteration over Taxonomy Connection: Custom Taxonomy Term A: 123
    Custom Taxonomy Term B: 456
    Iteration over Taxonomy Field: Custom Taxonomy Term A: 123
    Custom Taxonomy Term B: 456

    If it’s not working as expected, verify that the Pods Single Item block is inside Query Loop and Post Template blocks in the template List View.

    Here is the pods.json for this test configuration, from Pods Admin > Components > Import / Export Packages:

    {
        "@meta": {
            "version": "2.9.19",
            "build": 1693734775
        },
        "settings": {
            "types_only": "0",
            "watch_changed_fields": "0",
            "metadata_integration": "1",
            "metadata_override_get": "0",
            "media_modal_fields": "0",
            "session_auto_start": "0",
            "wisdom_opt_out": "1"
        },
        "pods": [
            {
                "name": "custom_taxonomy",
                "id": 7,
                "label": "Custom Taxonomies",
                "description": "",
                "type": "taxonomy",
                "storage": "meta",
                "label_singular": "Custom Taxonomy",
                "public": "1",
                "show_ui": "1",
                "hierarchical": "1",
                "rest_enable": "1",
                "_migrated_28": "1",
                "built_in_post_types_post": "1",
                "required": "0",
                "required_help_boolean": "0",
                "groups": [
                    {
                        "name": "more_fields",
                        "id": 8,
                        "label": "More Fields",
                        "description": "",
                        "weight": 0,
                        "fields": [
                            {
                                "name": "some_field",
                                "id": 20,
                                "label": "Some Field",
                                "description": "",
                                "weight": 0,
                                "type": "text",
                                "sister_id": "-- Select One --",
                                "required": "0",
                                "required_help_boolean": "0",
                                "text_allowed_html_tags": "strong em a ul ol li b i",
                                "text_max_length": "255",
                                "repeatable": "0",
                                "repeatable_format": "default",
                                "roles_allowed": "administrator",
                                "rest_pick_response": "array",
                                "rest_pick_depth": "1"
                            }
                        ]
                    }
                ]
            },
            {
                "name": "post",
                "id": 5,
                "label": "Post",
                "description": "",
                "type": "post_type",
                "storage": "meta",
                "object": "post",
                "_migrated_28": "1",
                "required": "0",
                "required_help_boolean": "0",
                "built_in_taxonomies_custom_taxonomy": "1",
                "groups": [
                    {
                        "name": "more_fields",
                        "id": 6,
                        "label": "More Fields",
                        "description": "",
                        "weight": 0,
                        "fields": [
                            {
                                "name": "relationship_field_to_custom_taxonomy",
                                "id": 9,
                                "label": "Relationship Field to Custom Taxonomy",
                                "description": "",
                                "weight": 0,
                                "type": "pick",
                                "pick_object": "taxonomy",
                                "pick_val": "custom_taxonomy",
                                "sister_id": "-- Select One --",
                                "pick_table": "-- Select One --",
                                "required": "0",
                                "required_help_boolean": "0",
                                "pick_format_type": "multi",
                                "pick_format_single": "dropdown",
                                "pick_format_single_help": "0",
                                "pick_format_multi": "list",
                                "pick_format_multi_help": "0",
                                "pick_display_format_multi": "default",
                                "pick_display_format_separator": ", ",
                                "pick_allow_add_new": "1",
                                "pick_taggable": "0",
                                "pick_show_icon": "1",
                                "pick_show_edit_link": "1",
                                "pick_show_view_link": "1",
                                "pick_limit": "0",
                                "pick_user_role": "Administrator",
                                "pick_post_status": "publish",
                                "pick_post_author": "0",
                                "repeatable": "0",
                                "repeatable_format": "default",
                                "roles_allowed": "administrator",
                                "rest_pick_response": "array",
                                "rest_pick_depth": "1"
                            }
                        ]
                    }
                ]
            }
        ]
    }

    Here is the literal content of the Pods Single Item block with the template from above, which can be pasted into the block editor:

    <!-- wp:pods/pods-block-single {"template_custom":"\u003cp\u003eCurrent Post: {@post_title}\u003c/p\u003e\n\n\u003cp\u003e\u003cstrong\u003eTerms assigned via Connection:\u003c/strong\u003e {@custom_taxonomy}\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eTerms assigned via relationship field:\u003c/strong\u003e {@relationship_field_to_custom_taxonomy}\u003c/p\u003e\n\u003cp\u003e\n\u003cstrong\u003eIteration over Taxonomy Connection:\u003c/strong\u003e \n[each custom_taxonomy]\n\t\u003ca href=\u0022{@permalink}\u0022\u003e{@name}\u003c/a\u003e: {@some_field}\u003cbr/\u003e\n[/each]\n\u003c/p\u003e\n\u003cstrong\u003eIteration over Taxonomy Field:\u003c/strong\u003e \n[each relationship_field_to_custom_taxonomy]\n\t\u003ca href=\u0022{@permalink}\u0022\u003e{@name}\u003c/a\u003e: {@some_field}\u003cbr/\u003e\n[/each]\n\u003c/p\u003e"} /-->

    And here is the full content of the default All Archives template with the Pods Single Item block added within Query Loop > Post Template:

    <!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
    
    <!-- wp:group {"tagName":"main","style":{"spacing":{"margin":{"top":"var:preset|spacing|70","bottom":"var:preset|spacing|70"}}},"layout":{"type":"constrained"}} -->
    <main class="wp-block-group" style="margin-top:var(--wp--preset--spacing--70);margin-bottom:var(--wp--preset--spacing--70)"><!-- wp:query-title {"type":"archive","align":"wide","style":{"spacing":{"margin":{"bottom":"var:preset|spacing|50"}}}} /-->
    
    <!-- wp:query {"queryId":1,"query":{"perPage":10,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true},"align":"wide","layout":{"type":"default"}} -->
    <div class="wp-block-query alignwide"><!-- wp:post-template {"align":"wide","layout":{"type":"grid","columnCount":3}} -->
    <!-- wp:post-featured-image {"isLink":true,"width":"100%","height":"max(15vw, 30vh)","align":"wide"} /-->
    
    <!-- wp:post-title {"isLink":true} /-->
    
    <!-- wp:post-excerpt /-->
    
    <!-- wp:post-date {"isLink":true} /-->
    
    <!-- wp:spacer {"height":"var(\u002d\u002dwp\u002d\u002dpreset\u002d\u002dspacing\u002d\u002d50)"} -->
    <div style="height:var(--wp--preset--spacing--50)" aria-hidden="true" class="wp-block-spacer"></div>
    <!-- /wp:spacer -->
    
    <!-- wp:pods/pods-block-single {"template_custom":"\u003cp\u003eCurrent Post: {@post_title}\u003c/p\u003e\n\n\u003cp\u003e\u003cstrong\u003eTerms assigned via Connection:\u003c/strong\u003e {@custom_taxonomy}\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eTerms assigned via relationship field:\u003c/strong\u003e {@relationship_field_to_custom_taxonomy}\u003c/p\u003e\n\u003cp\u003e\n\u003cstrong\u003eIteration over Taxonomy Connection:\u003c/strong\u003e \n[each custom_taxonomy]\n\t\u003ca href=\u0022{@permalink}\u0022\u003e{@name}\u003c/a\u003e: {@some_field}\u003cbr/\u003e\n[/each]\n\u003c/p\u003e\n\u003cstrong\u003eIteration over Taxonomy Field:\u003c/strong\u003e \n[each relationship_field_to_custom_taxonomy]\n\t\u003ca href=\u0022{@permalink}\u0022\u003e{@name}\u003c/a\u003e: {@some_field}\u003cbr/\u003e\n[/each]\n\u003c/p\u003e"} /-->
    <!-- /wp:post-template -->
    
    <!-- wp:query-pagination {"paginationArrow":"arrow","layout":{"type":"flex","justifyContent":"space-between"}} -->
    <!-- wp:query-pagination-previous {"label":"Newer Posts"} /-->
    
    <!-- wp:query-pagination-next {"label":"Older Posts"} /-->
    <!-- /wp:query-pagination --></div>
    <!-- /wp:query --></main>
    <!-- /wp:group -->
    
    <!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->
    Thread Starter helenagwyn

    (@helenagwyn)

    Thank you for your reply.
    To clarify and be more specific, I added a featured image (and some other fields) to the taxonomy.
    I want to show the featured image as a header on the taxonomy archive that I’m displaying. So not another related taxonomy, but the one being requested.
    I’m using Astra, so not a Block Theme.

    Plugin Support Paul Clark

    (@pdclark)

    “Featured image” is usually reserved for a WordPress-specific feature that is synonymous with post thumbnails, which only applies to post types.

    If you’ve used Pods to add an image to a taxonomy, what you’ve likely done is added an image field to taxonomy terms.

    Looking at the WP database schema, which is what Pods is using in most cases, fields added to terms are stored in wp_termmeta, so the appropriate WordPress core way of getting an image from term meta would be wp_get_attachment_url( get_term_meta( get_queried_object_id(), 'name_of_your_field', true ) ), where get_queried_object_id() returns the ID of the currently queried taxonomy term on a taxonomy archive, name_of_your_field is the image field key (not the label) you assigned in Pods, get_term_meta() will usually return an attachment ID from a Pods image field, and wp_get_attachment_url() will convert an attachment ID to an image URL. wp_get_attachment_image_src() can also be used to get the URL of a specific image size — it returns an array containing URL, width, and height.

    The Pods-specific equivalent would be pods( 'taxonomy_name', get_queried_object_id() )->field( 'name_of_your_field' ); or pods( 'taxonomy_name', get_queried_object_id() )->field( 'name_of_your_field._src' ) or pods( 'taxonomy_name', get_queried_object_id() )->field( 'name_of_your_field._src.medium' )

    All of these examples are PHP functions which would return a value. To output the value, echo would be used. To use it in a shortcode context, any of them could be wrapped in a shortcode, e.g., to create a shortcode [display-term-image]:

    <?php
    add_shortcode(
    	'display-term-image',
    	function( $atts, $content, $tag ) {
    		return sprintf(
    			'<img src="%s" />',
    			esc_url(
    				wp_get_attachment_url(
    					get_term_meta(
    						get_queried_object_id(),
    						'name_of_your_field',
    						true
    					)
    				)
    			)
    		);
    	}
    );

    Where name_of_your_field is the name of your field.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Not all taxonomy fields available on archive-page’ is closed to new replies.