WordPress.org

Ready to get started?Download WordPress

Forums

Media Categories
[resolved] example of use with custom taxonomy (21 posts)

  1. deepbevel
    Member
    Posted 2 years ago #

    this is what I have..

    custom taxonomy name (plural): My Gallery Categories

    (singular): My Gallery Category

    Custom Taxonomy Slug: "my-gallery-category"

    I'm using a custom post type for the taxonomy.

    I have mc taxonomy in functions.php:

    add_filter('mc_taxonomy', 'mc_filter_taxonomy');
    
    function mc_filter_taxonomy($taxonomy){
    
        if($taxonomy == 'category'){
            $taxonomy = 'my-gallery-category';
        }
    
        return $taxonomy;
    }

    and the meta box appears in the attachment editor. The category I created under "my gallery cateories" appears, The taxonomy assignment to the image saves. But I can't get the shortcode to output.

    `[gallery my-gallery-category="botanical"]'

    with "botanical" being the term name.

    Is there an example of how the code should look in mc taxonomy and in the shortcode when using a custom taxonomy? or am I doing it right?

    I know I'm close..please help!

    http://wordpress.org/extend/plugins/media-categories-2/

  2. deepbevel
    Member
    Posted 2 years ago #

    I'm fairly convinced I'm doing it right, and that it just doesn't work with custom taxonomies.

    I'm using my custom taxonomy for regular posts and it works fine, likewise, Media Categories works fine so long as it uses categories or tags as it's taxonomy.
    I don't know what else to test to confirm this, I've spent many hours..so I'll just live with it.

  3. Eddie Moya
    Member
    Plugin Author

    Posted 2 years ago #

    What version of wordpress are you using? What version of the plugin are you using?

    Unfortunatly I have not had much time recently to address bug reports. I will look into this one as soon as I can.

  4. deepbevel
    Member
    Posted 2 years ago #

    Thanks,

    plugin version 1.4.1 , wp 3.4.1.

    Great invention by the way, I've been trying to do this forever, with other plugins, but can never figure out how to get output.

    Aside from the custom tax issue, is their ANY other way to query attachments by the taxonomy other than teh gallery shortcode?

    I have other threads on this forum where I'm trying to figure out how to use this is my theme, some awkward solutions...but I found info on how to list terms and figured out how to mod my archives template with conditional shortcodes so the new tax outputs in a tag archive like it should (since I'm using "post_tag" as my media cat). So it's coming along.

    I'll be revisiting the custom taxonomy isuue I'm sure, post_tags works for me, but I'd love it if my taxonomy could be named more appropriatly.

  5. Eddie Moya
    Member
    Plugin Author

    Posted 2 years ago #

    Remember that attachments are a post type. So when you apply terms to an attachment, it the same thing as applying a term to a post or page. You can query them with all the typical ways you query for posts by taxonomy.

    get_posts(), query_posts(), WP_Query() - all of them, they can all get attachments filtered by taxonomy.

    By default wordpress doesnt let you do URI based queries of attachments, but by filtering pre_get_posts or request filters, you can even have post-type archives for attachments.

    Also, I have not actually had a chance to heavily debug this plugin on 3.4 or 3.4.1. If you notice I have not updated the version on the plugin page for that very reason. Based on the bug reports I've received, I suspect there have been some changes to the way the gallery shortcode work since 3.3.x

  6. deepbevel
    Member
    Posted 2 years ago #

    Whoa, I'm opening a real can o' worms here. All new stuff to me. Looking forward to exploring all the potential of this. Even as it is it's just great. Thanks again.

  7. deepbevel
    Member
    Posted 2 years ago #

    custom taxonomy working! must be because I was using a plugin to get the custom taxonomy before, now I just used a function for the taxonomy and the Media Categories shortcode works.

    I'll have to try some queries, i'd like to try to output the attachmants as thumbnails with meta, and in columns with paging like I've done with posts.

    the goal is to have the attachmants as thumbnails, but with title or author links below each to the parent post, attachment page or author page (any one would do). Optionlally, the thumbnails open in a lightbox that can navigate within the current page and style.

  8. Eddie Moya
    Member
    Plugin Author

    Posted 1 year ago #

    So you were using a plugin to create your custom taxonomies through an interface, rather than creating programmatically yourself right? If thats what you meant, what is the name of the plugin you used. When I get around to it, I'd like to see why its incompatible with that plugin.

    Thanks for the update, glad to know its working for you now.

  9. deepbevel
    Member
    Posted 1 year ago #

    Yes, that's right
    http://wordpress.org/extend/plugins/types/

    however, I should add that I tried 4 similar plugins for similar purposes, I wanted custom post types for my media category posts. But none were unable to show a featured image widget in the custom post type editor, even though they all had the settings for it. Not sure if it's realted.

    This is on a test site just for this plugin, with the latest wp and twenty ten and careful plugin compatibilty consideration at all times.

  10. deepbevel
    Member
    Posted 1 year ago #

    Also, I'm really desperate for pointers on getting started with outputting the media tagged images with queries, I've had 0 success.

    I'm dealing with 3 things that I've not delt with before:

    1} query attachments? I'm not sure how to think about this, because the media categories images don't seem to reference a post which they are attached to. In fact, they need the id if outside the loop.

    2}Query a custom taxonomy? I think I understand this just from reading, but not within the context of the above.

    3)custom post type for the custom media category taxonomy? ..about here it gets really muddy.

    I'm just looking for a way to output the images so they look like a gallery, but each has meta for it's parent post. Can I do it? Can you direct to any examples of somethng similar that I might try to mod?

    thanks

  11. Eddie Moya
    Member
    Plugin Author

    Posted 1 year ago #

    @deepbevel

    Sorry I could not follow up, I was very tied up with work.

    Do you still need help with this, did you figure out, did you give up?

  12. deepbevel
    Member
    Posted 1 year ago #

    Haven't revisited since my last post but this is as far as I got.

    <?php $images = get_posts( array('post_type' => 'attachment',
    'category__in' => array(42),
    'posts_per_page' => -1,
    'post_status' => 'inheret'
    
    )  );
    
    if ( !empty($images) ) {
    	foreach ( $images as $image ) {
    
    echo $image->post_title .'<br />';
    
    echo the_attachment_link($image->ID);?></br>
    
    <?php
    $first_name = get_the_author_meta('first_name',$user_id); 
    
    $user_info = get_userdata(1);
          $username = $user_info->user_login;
          $first_name = $user_info->first_name;
          $last_name = $user_info->last_name;
          echo "$user_name.";
    
    }
    }
    ?>

    It seems at one point I had at least the author name in the output for this, but now this isn't getting it. Otherwise it gets the images and the titles, which is better han before.

    On my site the images will be uploaded to a post. I need to be able to get the authors post link from the attachments, but not sure how because I don't understand how image files that are categorized outside of posts and pages can have an "author". Is what I'm trying to do possible?

    thanks!

  13. deepbevel
    Member
    Posted 1 year ago #

    had to remove

    'category__in' => array(42),

    Now it gets attachments with a link to the author posts page, which is exactly what I wanted, but now I have to make it get posts for just the custom taxonomy for the media categories..

    <?php $images = get_posts( array('post_type' => 'attachment',
    
    'posts_per_page' => -1,
    'post_status' => 'inheret'
    
    )  );
    
    if ( !empty($images) ) {
    	foreach ( $images as $image ) {
    
    echo $image->post_title .'<br />';
    
    echo the_attachment_link($image->ID);?></br>
    
    <?php
    $first_name = get_the_author_meta('first_name',$user_id); 
    
    $user_info = get_userdata(1);
          $username = $user_info->user_login;
          $first_name = $user_info->first_name;
          $last_name = $user_info->last_name;
          echo "$user_name.";
    
    echo  the_author_posts_link();
    
    }
    }
    ?>
  14. Eddie Moya
    Member
    Plugin Author

    Posted 1 year ago #

    I'm really unclear about what your trying to do. Sounds like you got the first part working, but now your trying to do something with a custom post type?

    This plugin wouldn't have anything to do with a custom post type - what it does is strictly for the built-in attachments post type. Is there something wrong with the plugin? Or something regarding the plugin that you need help with?

  15. deepbevel
    Member
    Posted 1 year ago #

    No, sorry, no custom post type, if that's in my code it's unintentional.

    I've been trying for a long time to output the media categories. That's all I'm trying to do, I need to do it without the shortcode because I need to include things like user name, term name, all the normal post meta stuff, with each image..

    I understand there's nothng specific to the plugin here, but I've never tried to output attachments as a custom taxonomy, so I figured this might be the place.

    I'm making big progress now, I can resolve the topic.
    Thanks for the great plugin, essential for what I'm trying to do and I'm learning so much in the process.

  16. Eddie Moya
    Member
    Plugin Author

    Posted 1 year ago #

    Generic example of getting media by a taxonomy.

    $images = get_posts(
       'post_type' => 'attachment',
       'tax_query' => array(
           array(
              'taxonomy' => 'your-chosen-taxonomy',
              'field' => 'slug', // can also be either term ID or Slug
              'terms' => array( 'term1', 'term2', 'term3' )
       )
    );

    This is not specific to Media Categories, this is just the native behavior of WordPress WP_Query. Once my plugin assigns a term to an image, they can be treated like any other post/taxonomy relationship.

    For more information on the tax_query parameter: http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

  17. deepbevel
    Member
    Posted 1 year ago #

    Thanks, I got that far, but I've hit a wall with the params, doesn't seem to be a way to get a post author name to display with the image.

    I thought that if the image is uploaded to a post, it would have that association, even if the image is not pulled from the post.

    At one point I thought I had it but it was showing the author of the post that was also accidently using the same media category as the image.

    Just to experiment i tried it will all the posts, but
    this produced an odd result, if I changed the author for one post in a media category, all posts in that media category changed to that same author.

    I tried 2 different functions that were supposed to make the attachement and post author the same. But neither worked for me.

  18. Eddie Moya
    Member
    Plugin Author

    Posted 1 year ago #

    Why dont you just get the post first, and then find the associated images? That way you'll already have the post and its post author.

  19. deepbevel
    Member
    Posted 1 year ago #

    thanks, I've been thinking the same. I wouldn't know how to set it up from scratch but I'll find something to get me going. All examples greatly appreciated..

  20. Eddie Moya
    Member
    Plugin Author

    Posted 1 year ago #

  21. deepbevel
    Member
    Posted 1 year ago #

    That worked for me, thanks!

    The only limitation is the post has to be assigned to the same media-category as the image in order to show the author link.

    Still, it allows images attached to a post to appear grouped in categories and include post meta, like the author posts link.

    The goal:
    A multi user art blog, each user with their own gallery-posts. Very much out of the box except for the admin area is customized per user role.

    In addition to appearing in the users own post, each image in the post can appear in one or more of several community-galleries.
    All images by all users which are categorized "portrait" appear in the portrait media-category, ect..

    Then, each image has a link back to the author posts page.

    So again, the only bummer is each media category selected for the images must also be selected for the post.

    Still, the post can appear with it's gallery in a category which is not a media-category. So I'll call it progress..

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.