attachment.php category if/else statements (5 posts)

  1. tgiokdi
    Posted 5 years ago #

    ok, here's my situation. Google's told me that I need to not have their ads on NSFW content, which I'm perfectly happy with. My problem is that the attachment.php file doesn't seems to be able to tell what category the attachment is in. I did some googling and found a previous wordpress support thread that mentioned using this:

    $post = get_post($ID);

    if ( is_object($post) ) :
    if ( ('attachment' == $post->post_type) && $post->post_parent && ($post->ID != $post->post_parent) ) :
    if ( in_category('images') ) { echo "THIS IMAGE IS SAFE FOR WORK"; }
    else { include "header-advert-nsfw.php"; };


    for the intent of this post, my blog only has two categories, NSFW and Images.

    now, this works, but only for some posts, and it's driving me crazy as to why it works on some and not others. from what I can tell, if the post was originally in the Images category and I edited it to be in the NSFW category, the code above will still think that it's in the Images category, and not the NSFW one. I've tried looking into the category tables in the database, but I can't make heads or tails of it.

    Anyone know what's going on here? why isn't the category being changed where this code can see it? is there alternate code that will work better with the current category database layout?

  2. tgiokdi
    Posted 5 years ago #

    from what I've found on the internets, apparently the category is NOT updated for attachments. anyone know how to update those categories? or even see them? I found that I can go through mysql and update them manually in the wp_term_relationships table, but there are thousands upon thousands of posts that need to be corrected.

  3. tgiokdi
    Posted 5 years ago #

    anyone know how to update the attachment categories?

  4. tgiokdi
    Posted 5 years ago #

    somehow, the other post that I had going about this was closed, if a mod could look into reopening that one, I would appreciate it.

  5. tgiokdi
    Posted 5 years ago #

    oh man, 3 months and two wordpress updates and the attachment.php theme file is still broken?

    in fact, it seems like it's even more broken now, with posts that were working fine before now returning the incorrect crap on them.

    does anyone know how to show content on the attachment page based on what the parent post's category is?

Topic Closed

This topic has been closed to new replies.

About this Topic