WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Add Meta Values To Custom Taxonomy For Custom Post Type (3 posts)

  1. WebTechGlobal
    Member
    Posted 3 years ago #

    I created a custom post type and some taxonomies. I'm trying to add values for the taxonomies I created. The meta boxes show on the Edit Post screen, but are never populated with values.

    Closest I get is new custom fields.

    Can someone please confirm what goes where on this function...

    add_metadata( $meta_type, $object_id, $meta_key, $meta_value );

    Thank you

    function eci_populatetaxonomy($recordarray,$csv,$filename,$set,$posttype,$postid)
    {
    	// first check that the post type exists in the taxonomy array
    	if(isset($csv['taxonomies'][$posttype]))
    	{
    		// loop through all set columns - for each column set in array we add that columns data to the taxonomy stored with it
    		foreach($csv['taxonomies'][$posttype] as $csvcolumn=>$tax)
    		{
    
    			//echo $csvcolumn.'= Column title in data used to extract data value from record array <br />';
    			//echo $tax.'= Taxonomy name i.e. MyTaxonomy <br />';
    
    			if($key != 'NA')
    			{
    				// add_metadata($meta_type, $object_id, $meta_key, $meta_value, $unique = false)
    
    				$sqlcolumn_clean = eci_cleansqlcolumnname($csvcolumn);
    				add_metadata('term', $postid, $tax, $recordarray[$sqlcolumn_clean]);// this adds custom fields
    
    				//add_metadata($posttype, $postid, $tax, $recordarray[$sqlcolumn_clean]);// this adds custom fields
    
    				//add_post_meta($postid, $postid, $tax, $recordarray[$sqlcolumn_clean]);
    			}
    		}
    	}
    }
  2. WebTechGlobal
    Member
    Posted 3 years ago #

    I still need help on this. Tidied up the area of code I need to complete to help it be a little clear what variables we have to deal with.

    I keep creating Custom Fields or nothing, whatever I do! I don't get it.

    function eci_populatetaxonomy($recordarray,$csv,$filename,$set,$posttype,$postid)
    {
    	// first check that the post type exists in the taxonomy array
    	if(isset($csv['taxonomies'][$posttype]))
    	{
    		// loop through all set columns - for each column set in array we add that columns data to the taxonomy stored with it
    		foreach($csv['taxonomies'][$posttype] as $csvcolumn=>$tax)
    		{
    
    			//echo $csvcolumn.'= Column title in data used to extract data value from record array <br />';
    			//echo $tax.'= Taxonomy name i.e. MyTaxonomy <br />';
    
    			if($key != 'NA')
    			{
    				// Post ID: $postid
    				// Custom Post Type: $posttype
    				// Taxonomy Name: $tax
    				// $recordarray[$csvcolumn]: data value
    
    				// what do I put here to add meta data to a post so that it
    				// populates custom meta boxes and not custom fields ?
    
    			}
    		}
    	}
    }
  3. WebTechGlobal
    Member
    Posted 3 years ago #

    I'm thinking it is this and I have tried it before. About to try again

    //wp_set_object_terms( 123, 'Bob', 'person' );
    //wp_set_object_terms( $object_id, $terms, $taxonomy, $append )
    wp_set_object_terms( $postid, $recordarray[$csvcolumn], $tax );

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.