WordPress.org

Forums

Enhanced Media Library
How can I auto tag attachments based on the post? (4 posts)

  1. toniweb
    Member
    Posted 1 year ago #

    Lets say I would like to create one Media category for each post,

    And let the code auto update the list,

    I tried something like (just to create the categorie, I'll figure how to set the attachments later):

    $parent_term = term_exists( $thePropTitle, 'attachment' ); // array is returned if taxonomy is given
    $parent_term_id = $parent_term['term_id']; // get numeric term id
    if ($parent_term !== 0 && $parent_term !== null) {
    
    	echo 'nye<br>';
    }else{
    	echo 'yay? '.$parent_term_id.'/'.$thePropTitle.'/<br>';
    
    	wp_insert_term(
    	  $thePropTitle, // the term
    	  'attachment', // the taxonomy
    	  array(
    	    'description'=> 'Tagged to '. $thePropTitle.'.',
    	  )
    	);
    }
    $parent_term = term_exists( $thePropTitle, 'attachment' );
    $parent_term_id = $parent_term['term_id'];
    echo 'term:' . $parent_term_id;

    But the item is not added to the media categories..

    I believe the taxonomie name (attachment) that i'm using is incorrect?

    Anybody tried to Do something like this? or knows what am I missing here?

    https://wordpress.org/plugins/enhanced-media-library/

  2. webbistro
    Member
    Plugin Author

    Posted 1 year ago #

    Hello,

    Sorry I wasn't able to reply earlier. Is the problem still actual for you?

    Nadia

  3. toniweb
    Member
    Posted 1 year ago #

    Actually...yeah,

    I was able to autocreate the taxonomies, but I have no clue how to autotags the attachmens to the taxonomies? (hopefully update it when add/remove)

    Any thoughts?

    Thanks!

  4. webbistro
    Member
    Plugin Author

    Posted 1 year ago #

    Sorry, but it's not quite clear to me what is your task. As far as I could understand you need

    1. to create new media category each time you create new post
    2. to assign attachments of this post to this media category

    Am I correct?

    Nadia

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Enhanced Media Library
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.