Support

Account

Forum Replies Created

  • Do you want the “else” color to be random?

  • It looks like you are using a text field for the hair_color field rather than a select/option field.

    So try any of these:

    <?php 
     
    $queried_object = get_queried_object(); 
    $taxonomy = $queried_object->taxonomy;
    $term_id = $queried_object->term_id;  
    
    $hair_color = get_field('hair_color', $taxonomy . '_' . $term_id);
    
    echo $hair_color;
     
    ?>
    <?php
     
    global $post;
     
    $taxonomy = "someting";
    
    $terms = get_the_terms($post->ID, $taxonomy);
     
    if( !empty($terms) )
    {
    	$term = array_pop($terms);
     
    	$custom_field = get_field('hair_color', $taxonomy . '_' . $term->term_id );
     
    	// do something with $custom_field
    }
     
    ?>

    See this example for more info: http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-a-taxonomy-term/

    If you do want to use a Radio Button field type and have them choose from a list of hair colors, then this might work too (I think):

    <?php
    $field = get_field_object('hair_color', $taxonomy . '_' . $term->term_id);
    $value = get_field('hair_color');
    $label = $field['choices'][ $value ];
    
      echo '<p>' . $label . '</p>' ;

    Probably didn’t work before due to being text field rather than select/radio field and the $taxonomy value not being defined, although not sure…

  • Thanks! 🙂

  • Something like this might be what you’re looking for:

    <?php
    
          $rows = get_field('repeater');
    
            if($rows) {
    
                echo '<h3>Results</h3>';
                echo '<ul>';
    
                $row_count = count($rows);
                $i = rand(0, $row_count - 1);
    
                while(has_sub_field('repeater')) {
    
                      $field = get_sub_field_object('img_title');
                      $value = get_sub_field('img_title');
                      $label = $field['choices'][ $value ];
    
                      echo '<li><a href="' . $rows[$i]['img'] . '">' . $rows[$i][$lable] . '</a></li>' ;
                      $i++;
    
              }
    
              echo '</ul>'; 
           }
                
    ?>
  • Try this, probably won’t work but who knows… 🙂

    <?php function get_currentuserinfo() {
    
    		global $current_user;
    		$other_page = $current_user->user_login;
    		$field = get_field('favourite_movie', $other_page);
    
    		if( is_page( $other_page ) ) {
    			echo $field;
    		}	
    	}
    ?>

    If not, should post the whole code since you mentioned using a repeater.

  • $field = get_field_object('hair_color');
     $value = get_field('hair_color');
     $label = $field['choices'][ $value ];
    
      echo '<p>' . $label . '</p>' ;

    $label should display the hair color.

  • You can also name a select field $footer with options yes/no. Then just do a conditional statement based on the $footer value.

    <?php
    
    if(get_field('$footer') == "yes")
    {
        //...
    } else {
    
       //...
    }
    
    ?>

    or just

    <?php if( get_field('$footer') ): ?>
    	 //...
    <?php endif; ?>

    As far as returning null, you can skip the option to show the footer and just check if data has been entered into each of the footer column fields. If no, the field wont show.

    <?php 
      
      $col_1 = get_field('$footer_col_1');
      $col_2 = get_field('$footer_col_2');
      $col_3 = get_field('$footer_col_3');
    
      if($col_1) {
    	echo $col_1;
      }
    
      if($col_2) {
    	echo $col_2;
      }
    
      if($col_3) {
    	echo $col_3;
      }
    
    ?>

    Lots of options, so just go with the method that works best for you.

  • You could set it up like this (I think):

    “display_footer” => Field Type = True/False
    “footer_col_1” => Field Type = Text Area/Editor
    “footer_col_2” => Field Type = Text Area/Editor
    “footer_col_3” => Field Type = Text Area/Editor

    With this code:

    <?php
    
    	$footer = get_field('display_footer' );
    
    	if($footer)
    		{
    
    		$footer_col_1 = get_field('footer_col_1' );
    		$footer_col_2 = get_field('footer_col_2' );
    		$footer_col_3 = get_field('footer_col_3' );
    
    		echo '<h3>Footer</h3>';
    		echo '<ul>';
    
    		echo '<li>' . $$footer_col_1 . '</li>';
    		echo '<li>' . $$footer_col_2 . '</li>';
    		echo '<li>' . $$footer_col_3 . '</li>';
    
    		echo '</ul>';
    		}
    
    ?>
  • Have you tried setting the repeater image to table? Then upload all images at once and the repeater should automatically add a row for each image.

  • Maybe I’m not seeing it, but looks like you’re missing a opening php tag <?php in front of the if(get_field(‘carousel_items’)):

  • This should work:

    – Create a Field Group
    – Add a Repeater
    – Add Sub Fields to Repeater
    – Add two Radio Button Fields to Field Group (Not as sub fields in the repeater!)

    I have these fields in my Field Group:
    “Repeater” => Repeater Field
    “IMG” => Repeater Sub Field, Field Type = Image, Return Value must be “Image ID”
    “IMG Title” => Repeater Sub Field, Field Type = Text
    “Row Sort” => Field Type = Radio Button, Default Value = “default”, Choices are set to:

    default : default
    random : random
    reverse : reverse

    “Row Limit” => Field Type = Radio Button, Option “Add ‘other’ choice to allow for custom values” is checked. Default Value = “3”, Choices are set to:

    1 : 1
    2 : 2
    3 : 3

    When the user creates a post, they can limit the number of Repeater rows to show and choose how the rows should be sorted (e.g. Random Order + Displaying 5 Rows).

    Tested and works, could probably clean code up or do some of it differently… this is what my tired mind came up with 🙂

    <?php
     
    $row_sort = get_field('row_sort' ); // radio button: random/reverse/default
    $row_limit = get_field('row_limit'); // radio button: 1/2/3/Custom
    
    $rows = get_field('repeater' );
    $sub_field = has_sub_field('repeater');
    
    $img = get_sub_field('img');
    $img_title = get_sub_field('img_title');
    
    if($rows) {
    
        echo '<h3>My List</h3>';
        echo '<ul>';
    
          for($i=0; $i < $row_limit; $i++) // Limits Rows based on field "Row Limit"
              {
    
                if($row_sort == "random") { // Random Order
    
                  /* Display Images Randomly (e.g. If 10 images have been added and Row Limit is set to 5, 5 Random Images will Display), $image[0] will pull the image links */
    
                  $rand_row = $rows[ array_rand( $rows ) ];
                  $rand_row_image = $rand_row['img' ];
                  $image = wp_get_attachment_image_src( $rand_row_image, 'full' );
    
                  echo '<li>';
                  echo $image[0]; // Return Value for Image must be set to "Image ID"
                  echo '</li>';
    
                } elseif($row_sort == "reverse") { // Reversed Order
    
                  /* Displays links to images in reversed order. If 10 images and Row Limit is set to 5, Images 10, 9, 8, 7, 6 will display */
    
                  $rowArray = get_field('repeater' );
                  $reversedArray = array_reverse( $rowArray );
                  
                      if($reversedArray) {
                      
                        $reversedArray = has_sub_field('repeater');
                        $img = get_sub_field('repeater');
                        $img_title = get_sub_field('repeater');
    
                        echo '<li><a href="' . $img . '">' . $img_title . '</a></li>';
    
                      }
    
                } else { // Default Order
    
                  /* Displays list of Image Titles like it normally would, but limited to Row Limit */
    
                    $default = get_field('repeater' );
                    $default = has_sub_field('repeater');
                  
                      if($default) { 
                          $img_title = get_sub_field('repeater');
                           
                          echo '<li>' . $img_title . '</li>';
                      }
    
                }
          
          }
                        
        echo '</ul>';
        
    } ?>
  • Thanks elliot, you’re right, putting it in the while loop doesn’t make sense. Have been going on too little sleep lately… Thanks for all your hard work and support, buying the add-ons and using your plugin has been life saver!

  • This reply has been marked as private.
  • This reply has been marked as private.
  • Thanks for the reply and sorry about that, a bit hard to explain. Will try again.

    Each post will have several sections, and one of the sections will consist of 10 links each linking to a chart/image. While the images/charts will be different for each post, the titles for the links will be the same in every post.

    So I would have a section like this:

    • Title for Link 1 to Image 1
    • Title for Link 2 to Image 2
    • Title for Link 3 to Image 3
    • Title for Link 4 to Image 4
    • etc…

    While the titles to the links opening the images in a lightbox will be the same in each post, the images will be different.

    So Ideally I would have some sort of solution to where I could just upload all images at once. Then each image would be matched with the corresponding title (pre-defined title 1 to image 1, pre-defined title 2 to image 2, etc.), and I’d use a function to display the image links through the template used for my custom post type.

    I hope that makes sense, if not I’ll try to put together an example tomorrow morning.

    Thanks a lot for your help 🙂

Viewing 17 posts - 26 through 42 (of 42 total)