Support

Account

Home Forums Front-end Issues Calling custom 'color' field from custom taxonomy

Solving

Calling custom 'color' field from custom taxonomy

  • Hi All –

    I’ve created a custom taxonomy called “event_tag” and a color custom field called “term_color” that I’ve assigned to the taxonomy. However, I’m having trouble calling up the assigned color for each event_tag. In the database I can see that the information is being stored like this:

    event_tag_1_term_color

    I then have another sub_field in a repeater field that allows the user to select from the terms in a multiple checkbox field to assign one or more to an actual event – which is called “pro_perf_time_tag”.

    With everything I’ve read I should be able to pull up the color using something like this, but it isn’t working:

    
    $date_tags = get_sub_field('pro_perf_time_tag'); 
    										if($date_tags) {
    										foreach($date_tags as $date_tag) {
    	$t_id = $date_tag->term_id;
            $t_data = get_option("event_tag_$t_id");
            echo $t_data['term_color'];
    }
    }
    

    Any thoughts or pointers on how I should look at it next? Thanks and forgive my limited PHP knowledge.

  • Can I ask if you have read through the documentation for the repeater field, and have correctly used a has_sub_field loop?

    Perhaps you could show all the loop code, that would help find the issue

  • Also, as this is the new support forum (currently in beta) I have a few questions for you if you don’t mind:

    1. Why did you not place your code within code tags as seen in the wysiwyg editor?
    2. Why did you not place the topic in the ‘General’ category when it would be better placed in ‘Repeater field’ or ‘Front end’?
    3. Why did you not enter any tags for the topic for users to search for in the future?

    Thanks

  • Elliot –
    Here is the full section of code.

    <?php if(get_field('pro_perf')) { 
    	   while(has_sub_field('pro_perf')) {
    	        $date_id = 1;
    	        echo '<p> ' . get_sub_field('pro_perf_date') . '<br /> ';
    		if(get_sub_field('pro_perf_time_repeat')) {
    	        	while(has_sub_field('pro_perf_time_repeat')) {
    			    if($date_id <= 1 ) {
                                   $date_tags = get_sub_field('pro_perf_time_tag');
    			       if($date_tags) {
                                    foreach($date_tags as $date_tag) {
    	$t_data = get_option("event_tag_$date_tag->term_id_term_color");
    	echo $t_data;
    echo '<span class="tagbox" style="background:' . $color . ';">' . $date_tag->slug . '</span>';
    				}
    																			
    echo '<a class="date" href="' . get_sub_field('pro_perf_time_link') . '">' . get_sub_field('pro_perf_time') . '</a>';
    
    				} else {
    
     echo '<a class="date" href="' . get_sub_field('pro_perf_time_link') . '">' . get_sub_field('pro_perf_time') . '</a>';
    				}
    
    			} else {
    
    									$date_tags = get_sub_field('pro_perf_time_tag');
                                   if($date_tags) {
                                           foreach($datetags as $datetag) {
    									      echo '<span class="tagbox"> ' . $date_tag->slug . ' </span>';
                                           }
    									
    echo ' | <a class="date" href="' . get_sub_field('pro_perf_time_link') . '">' . get_sub_field('pro_perf_time') . '</a>';
    				} else {
    echo ' | <a class="date" href="' . get_sub_field('pro_perf_time_link') . '">' . get_sub_field('pro_perf_time') . '</a>';
    			        }
         			}
    			$date_id ++;
    		}
    	}
    
    	echo '</p>';
    }
    }?>
    

    Also, to answer your other questions, in my rushed state to post, I did not see the code button as an option. I am also fairly new to forums like this and the truth is it was just laziness and frustration but in the future I will make sure to properly address those issues and be a better community member.

  • Thanks for the full code.

    This is great to look at, however, can I ask you to very clearly describe the issue. You say the issue is getting the date tags data.

    Is the issue using the get_sub_field like in the following code?

    
    $date_tags = get_sub_field('pro_perf_time_tag'); 
    

    Or is the issue looping through the $date_tags array and loading the data.

    Can you please go through your ode line by line and debug the variables.

    Thanks
    Elliot

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Calling custom 'color' field from custom taxonomy’ is closed to new replies.