I’ve created a custom taxonomy called imagetags using the following code:
// Register Custom Taxonomy
function custom_imagetags_taxonomy() {
$labels = array(
'name' => _x( 'Image Tags', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'Image Tag', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'Image Tags', 'text_domain' ),
'all_items' => __( 'All Image Tags', 'text_domain' ),
'parent_item' => __( 'Parent Image Tag', 'text_domain' ),
'parent_item_colon' => __( 'Parent Image Tag:', 'text_domain' ),
'new_item_name' => __( 'New Image Tag', 'text_domain' ),
'add_new_item' => __( 'Add New Image Tag', 'text_domain' ),
'edit_item' => __( 'Edit Image Tag', 'text_domain' ),
'update_item' => __( 'Update Image Tag', 'text_domain' ),
'separate_items_with_commas' => __( 'Separate Image Tags with Commas', 'text_domain' ),
'search_items' => __( 'Search Image Tags', 'text_domain' ),
'add_or_remove_items' => __( 'Add or Remove Image Tags', 'text_domain' ),
'choose_from_most_used' => __( 'Choose From Popular Image Tags', 'text_domain' ),
);
$rewrite = array(
'slug' => 'imagetags',
'with_front' => true,
'hierarchical' => false,
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'rewrite' => $rewrite,
);
register_taxonomy( 'imagetags', 'attachment', $args );
}
// Hook into the 'init' action
add_action( 'init', 'custom_imagetags_taxonomy', 0 );
Now I’m trying to create a template page to show images that fit a particular imagetag.
I started by naming a file taxonomy-imagetags.php
I’m stuck on the type of loop to use.
I’ve tried a few and nothing has worked.
Would appreciate any help.
The issue is with the
post_status
argument of the default query generated for your taxonomy terms. If you change the status via thepre_get_posts
action toinherit
orany
, you can get attachments to show up.however– is this the correct way to do this- I honestly don’t know. This will show attachments to posts that are drafts, and maybe private. I haven’t tested it thoroughly so beware.
Perhaps someone else can chime in with more knowledge and info.
I’ve found this plugin. Though I haven’t investigated it, seems like it may solve my problem.
Media Tags Plugin.