• Resolved Rose

    (@eos-rose)


    I have created a group called ‘Contributor’ (may be duplicated). Within that group I have have two fields: ‘contributor_name’ (no duplicates) and ‘contributor_role’ (may be duplicated). I need to create a function that will allow me to list ONLY the names of contributors who have a value of “Artist” in the ‘contributor_role’ field. I could do this if it wasn’t a duplicate field using the following code:

    if(!function_exists('contributor')){
    	function contributor(){
    		global $post;
    		$Contributors = get_group('Contributor');
    		foreach($Contributors as $Contributor){
    			if($Contributor['contributor_role'][1] == 'Artist') {
    				echo $Contributor['contributor_name'][1];
    			}
    		}
    	}
    }

    How do I modify the code to account for the fact that some of my contributors have multiple roles?

    https://www.ads-software.com/extend/plugins/magic-fields/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author hunk

    (@hunk)

    Hi Eos Rose

    if(!function_exists('contributor')){
    	function contributor(){
    		global $post;
    		$Contributors = get_group('Contributor');
    		foreach($Contributors as $Contributor){
                           //change this line
    			if( in_array('Artist',array_values($Contributor['contributor_role']) ) ) {
    				echo $Contributor['contributor_name'][1];
    			}
    		}
    	}
    }
    Thread Starter Rose

    (@eos-rose)

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Magic Fields] Return content only if a duplicate field in a group includes a specific value’ is closed to new replies.