Query multiple nested taxonomies
-
I’ve got a couple taxonomy relationships that I assign to a custom post type (artist -> has_many albums -> has_many reviews) and I can’t for the life of me figure out how to query based on the relationships. Currently I have an artist page (archive page?) and I’m trying to list all the albums (in order of publish date) and the reviews associated with each album. My hacky method is the following, but I’d like to be able to order the “artist_albums” relationships by publish date and can’t seem to figure out how to access the album pods’ metadata.
<?php $pod = pods(); $albums = $pod->field( 'artist_albums' ); ?> <ul class="artist-album-list"> <?php foreach ($albums as $album) { $args = array( 'post_type' => 'review', 'tax_query' => array( array( 'taxonomy' => 'album', 'field' => 'term_id', 'terms' => $album['term_id'], ), ), ); $the_query = new WP_Query( $args ); ?> <li class="artist-album"> <div class="album-cover-thumb"> <?php $thumb_id = get_term_meta( $album['term_id'], 'cover', true ); echo wp_get_attachment_image( $thumb_id, 'medium' ); ?> </div> <div class="artist-album-reviews"> <h2 class="album-name"><?php echo $album['name']; ?></h2> <?php if ( $the_query->have_posts() ) { echo '<h3 class="reviewers">Reviewers:</h3>'; echo '<ul>'; while ( $the_query->have_posts() ) { $the_query->the_post(); $id = get_the_ID(); echo "<li class='reviewer-row'><a href='".get_the_permalink()."'><div class='review-author'>".get_the_author()."</div><div class='review-date'>". get_the_time('m/d/Y', $id)."</div></a></li>"; } echo '</ul>'; wp_reset_postdata(); } ?> </div> </li> <?php } ?> </ul>
{ "@meta": { "version": "3.0.8", "build": 1700763532 }, "settings": { "types_only": "0", "watch_changed_fields": "1", "metadata_integration": "1", "metadata_override_get": "0", "session_auto_start": "0", "wisdom_opt_out": "", "media_modal_fields": "1", "active_components": [ "advanced-relationships", "migrate-packages", "table-storage", "templates" ] }, "pods": [ { "name": "album", "id": 1007, "label": "Albums", "description": "", "type": "taxonomy", "storage": "meta", "label_singular": "Album", "public": "1", "show_ui": "1", "hierarchical": "0", "rest_enable": "1", "_migrated_28": "1", "required": "0", "built_in_post_types_review": "1", "pfat_enable": "1", "show_in_menu": "1", "menu_location": "objects", "menu_position": "0", "show_in_nav_menus": "1", "show_tagcloud": "1", "show_in_quick_edit": "1", "show_admin_column": "1", "menu_name": "Albums", "write_all": "album", "rest_api_field_mode": "value", "read_all": "1", "built_in_post_types_attachment": "1", "rest_route": "\/pods\/v1\/pods\/1007", "pfat_single": "Album info", "built_in_post_types_review2": "1", "groups": [ { "name": "more_fields", "id": 1008, "label": "More Fields", "description": "", "weight": 0, "fields": [ { "name": "release_year", "id": 1009, "label": "Release Year", "description": "", "weight": 0, "type": "text", "sister_id": "-- Select One --", "required": "0", "repeatable": "0", "repeatable_format": "default", "roles_allowed": "administrator", "rest_pick_response": "array", "rest_pick_depth": "1", "text_allowed_html_tags": "strong em a ul ol li b i", "text_max_length": "4" }, { "name": "album_artist", "id": 1014, "label": "Artist", "description": "", "weight": 1, "type": "pick", "pick_object": "taxonomy", "pick_val": "artist", "sister_id": "1013", "pick_table": "-- Select One --", "required": "1", "pick_format_type": "single", "pick_format_single": "autocomplete", "pick_format_multi": "list", "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" }, { "name": "record_label", "id": 1078, "label": "Record Label", "description": "", "weight": 2, "type": "text", "sister_id": "-- Select One --", "required": "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": "cover", "id": 35586, "label": "cover", "description": "", "weight": 3, "type": "file", "sister_id": "-- Select One --", "required": "0", "file_format_type": "single", "file_uploader": "attachment", "file_type": "images", "file_attachment_tab": "browse", "file_upload_dir": "wp", "file_edit_title": "1", "file_show_edit_link": "0", "file_linked": "0", "file_limit": "0", "file_field_template": "rows", "file_add_button": "Add File", "file_modal_title": "Attach a file", "file_modal_add_button": "Add File", "file_wp_gallery_link": "file", "file_wp_gallery_columns": "3", "file_wp_gallery_size": "thumbnail", "repeatable": "0", "repeatable_format": "default", "roles_allowed": "administrator", "rest_pick_response": "array", "rest_pick_depth": "1" } ] } ] }, { "name": "artist", "id": 1011, "label": "Artists", "description": "", "type": "taxonomy", "storage": "meta", "label_singular": "Artist", "public": "1", "show_ui": "1", "hierarchical": "0", "rest_enable": "1", "_migrated_28": "1", "show_in_menu": "1", "menu_name": "Artists", "menu_location": "objects", "show_in_nav_menus": "1", "show_tagcloud": "1", "show_in_quick_edit": "1", "rewrite": "1", "rewrite_with_front": "1", "rewrite_hierarchical": "1", "capability_type": "default", "capability_type_custom": "artist", "query_var": "0", "sort": "0", "built_in_post_types_review": "1", "read_all": "1", "built_in_post_types_review2": "0", "pfat_enable": "0", "pfat_filter_single": "get_the_archive_description", "pfat_single": "Artist", "pfat_append_single": "replace", "groups": [ { "name": "more_fields", "id": 1012, "label": "More Fields", "description": "", "weight": 0, "fields": [ { "name": "artist_albums", "id": 1013, "label": "Albums", "description": "", "weight": 0, "type": "pick", "pick_object": "taxonomy", "pick_val": "album", "sister_id": "1014", "pick_table": "-- Select One --", "required": "0", "pick_format_type": "multi", "pick_format_single": "dropdown", "pick_format_multi": "autocomplete", "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", "rest_read": "1", "rest_write": "1" }, { "name": "website", "id": 1015, "label": "Website", "description": "", "weight": 1, "type": "website", "sister_id": "-- Select One --", "required": "0", "website_format": "normal", "website_allow_port": "0", "website_clickable": "0", "website_new_window": "0", "website_nofollow": "0", "website_max_length": "255", "website_html5": "0", "repeatable": "0", "repeatable_format": "default", "roles_allowed": "administrator", "rest_pick_response": "array", "rest_pick_depth": "1" }, { "name": "sort_name", "id": 1079, "label": "Sort Name", "description": "", "weight": 2, "type": "text", "sister_id": "-- Select One --", "required": "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": "review", "id": 1005, "label": "Reviews", "description": "", "type": "post_type", "storage": "meta", "label_singular": "Review", "public": "1", "show_ui": "1", "rest_enable": "1", "supports_title": "1", "supports_editor": "1", "_migrated_28": "1", "built_in_taxonomies_album": "1", "supports_comments": "1", "pfat_enable": "1", "pfat_single": "Review Page", "pfat_append_single": "replace", "built_in_taxonomies_category": "0", "built_in_taxonomies_link_category": "0", "built_in_taxonomies_post_tag": "0", "supports_author": "1", "default_status": "draft", "pfat_archive": "Reviews", "pfat_append_archive": "replace", "pfat_filter_archive": "the_excerpt", "has_archive": "1", "rewrite": "1", "pfat_filter_single": "the_content", "pfat_run_outside_loop": "0", "built_in_taxonomies_artist": "1", "groups": [ { "name": "more_fields", "id": 1006, "label": "More Fields", "description": "", "weight": 0, "fields": [ { "name": "rating", "id": 44934, "label": "Rating", "description": "", "weight": 0, "type": "text", "sister_id": "-- Select One --", "required": "0", "text_allowed_html_tags": "strong em a ul ol li b i", "text_max_length": "3", "repeatable": "0", "repeatable_format": "default", "roles_allowed": "administrator", "enable_conditional_logic": "0", "rest_pick_response": "array", "rest_pick_depth": "1", "text_trim": "1", "text_trim_p_brs": "1", "text_trim_extra_lines": "1", "text_trim_lines": "1" } ] } ] }, { "name": "user", "id": 44936, "label": "User", "description": "", "type": "user", "storage": "meta", "object": "user", "_migrated_28": "1", "pfat_enable": "0", "pfat_filter_single": "get_the_author_description", "pfat_filter_archive": "get_the_author_description", "write_all": "user", "rest_api_field_mode": "value", "rest_enable": "0", "pick_object": "custom-simple", "required": "0", "groups": [ { "name": "more_fields", "id": 44937, "label": "More Fields", "description": "", "weight": 0, "fields": [ { "name": "test", "id": 47261, "label": "test", "description": "", "weight": 0, "type": "text", "sister_id": "-- Select One --", "required": "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", "enable_conditional_logic": "0", "rest_pick_response": "array", "rest_pick_depth": "1" } ] } ] } ], "templates": [ { "name": "Album info", "code": "<div id=\"album-info\">\r\n\t<div class=\"album-cover\">\r\n\t\t{@album.cover._img.medium}\r\n\t<\/div>\r\n\t<div>\r\n\t\t{@album.album_artist}\r\n\t<\/div>\r\n\t<div>\r\n\t\t{@album}\r\n\t<\/div>\r\n\t<div>\r\n\t\tReleased: {@album.release_year}<br \/>\r\n\t\t{@album.record_label}\r\n\t<\/div>\r\n<\/div>", "id": 1020, "_edit_lock": "1700263218:3", "_edit_last": "3", "admin_only": "0", "restrict_capability": "0", "show_restrict_message": "0", "_pods_capability_allowed": [ "" ], "pod_reference": { "pod": "album" } }, { "name": "Artist", "code": "<div class=\"artist-album-list\">\r\n\t[each artist_albums]\r\n\t<div class=\"artist-album\">\r\n\t\t<div class=\"album-cover-thumb\">\r\n\t\t\t{@cover._img.thumbnail}\r\n\t\t<\/div>\r\n\t\t<div class=\"artist-album-reviews\">\r\n\t\t\t<div class=\"album-name\">{@name}<\/div>\r\n\t\t\tReviewers:\r\n\t\t\t<?php echo $obj->reviews; ?>\r\n\t\t\t[each album_reviews]\r\n\t\t\t<div class=\"reviewer-row\">{@post_author.display_name} - {@post_date}<\/div>\r\n\t\t\t[\/each]\r\n\t\t<\/div>\r\n\t<\/div>\r\n\t[\/each]\r\n<\/div>", "id": 83473, "_edit_lock": "1700691822:3", "_edit_last": "3", "admin_only": "0", "restrict_capability": "0", "show_restrict_message": "0", "_pods_capability_allowed": [ "" ], "pod_reference": { "pod": "artist" } }, { "name": "Review Page", "code": "<div id=\"album-info\">\r\n\t<div class=\"album-cover\">\r\n\t\t{@album.cover._img.medium}\r\n\t<\/div>\r\n\t<div class=\"album-title\">\r\n\t\t{@album.name}\r\n\t<\/div>\r\n\t<div class=\"album-artist\">\r\n\t\t<a href=\"{@album.album_artist.permalink,esc_url}\">{@album.album_artist.name}<\/a>\r\n\t<\/div>\r\n\t<div class=\"album-publish\">\r\n\t\t{@album.record_label}, {@album.release_year}\r\n\t<\/div>\r\n\t<div class=\"album-website\">\r\n\t\t<a href=\"{@album.album_artist.website}\" target=\"_blank\" rel=\"noopener\">{@album.album_artist.website}<\/a>\r\n\t<\/div>\r\n<\/div>\r\n<div id=\"reviewer\">\r\n\t<b>Reviewed by<\/b> {@post_author.display_name}<br \/>\r\n\t<b>Published on<\/b> {@post_date, return_date_only}\r\n<\/div>\r\n<div id=\"review-content\">\r\n\t{@post_content}\r\n<\/div>\r\n<div id=\"review-rating\">\r\n\tRating: <span class=\"rating\">{@rating}<\/span>\r\n<\/div>", "id": 83351, "_edit_lock": "1700523034:3", "_edit_last": "3", "admin_only": "0", "restrict_capability": "0", "show_restrict_message": "0", "_pods_capability_allowed": [ "" ], "pod_reference": { "pod": "review" } }, { "name": "Reviews", "code": "<div class=\"pod-review-container\">\r\n <div class=\"box sidebar\">\t\t\r\n\t <div class=\"album-cover\">\r\n\t\t <a href=\"{@guid}\">{@album.cover._img.medium}<\/a>\r\n\t\t<\/div>\r\n\t<\/div>\r\n\t<div class=\"box sidebar2\">\r\n\t\t<div class=\"list-review-title\">\r\n\t\t\t{@album.name}\r\n\t\t<\/div>\r\n\t\t<div class=\"list-review-artist\">\r\n\t\t\t{@album.album_artist.name}\r\n\t\t<\/div>\r\n\t\t<div class=\"list-review-reviewer\">\r\n\t\t\tReviewer: {@post_author.display_name}\r\n\t\t<\/div>\r\n\t\t<div class=\"list-review-date\">\r\n\t\t\t<a href=\"{@guid}\">{@post_date, return_date_only}<\/a>\r\n\t\t<\/div>\t\r\n\t<\/div>\r\n<\/div>", "id": 73142, "_edit_lock": "1700000971:3", "_edit_last": "3", "admin_only": "0", "restrict_capability": "0", "show_restrict_message": "0", "_pods_capability_allowed": [ "" ], "pod_reference": { "pod": "review" } } ] }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- You must be logged in to reply to this topic.