Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • Hi Nuro, that’s a no on that but thank you for your suggestion.

    It’s crazy. It seems so easy yet just doesn’t work.

    Trying it normally with manual ID of page like:

    <?php
    $other_page = 890;
    ?>
    <?php the_field('field_name', $other_page); ?>

    …works great so the data IS being passed from the other page. I then had another idea of trying this way:

    <?php
    global $current_user;
    get_currentuserinfo();
    $username = $current_user->user_login;
    $other_page = $username;				
    ?>
    <p><?php the_field('favourite_movie', $other_page); ?></p>

    …which didn’t work either.

    The username of the current user IS also working when I ask for it conventionally:

    <?php global $current_user;
          get_currentuserinfo();
          echo 'Username is ' . $current_user->user_login . "\n";
    ?>

    Baffled.

    Elliot, how can I debug this? I’ve tried dumping the values:

    <?php
    global $current_user;
    get_currentuserinfo();
    
    $other_page = $current_user->user_login;
    $values = get_field('favourite_movie');
    var_dump($values);
    ?>

    and get bool(false) printed out?

  • 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…

  • Ok, managed to solve it by swapping the SQl round a little, like so:

    			$rows = $wpdb->get_results($wpdb->prepare( 
    			"
    			SELECT * 
    			FROM wp_postmeta
    			WHERE meta_key LIKE %s AND meta_value LIKE %s ORDER BY meta_value ASC",
    			'dates_%_available_dates', ''.$year.''.$month.'%', 			
    			""		
    			));	
  • Hi,

    Thank you, but I get an empty value.

    a var_dump($field) is empty too.
    This is the return:

    array(17) { [“key”]=> string(16) “field_hair_color” [“label”]=> string(0) “” [“name”]=> string(10) “hair_color” [“type”]=> string(4) “text” [“order_no”]=> int(1) [“instructions”]=> string(0) “” [“required”]=> int(0) [“id”]=> string(20) “acf-field-hair_color” [“class”]=> string(4) “text” [“conditional_logic”]=> array(3) { [“status”]=> int(0) [“allorany”]=> string(3) “all” [“rules”]=> int(0) } [“default_value”]=> string(0) “” [“formatting”]=> string(4) “html” [“maxlength”]=> string(0) “” [“placeholder”]=> string(0) “” [“prepend”]=> string(0) “” [“append”]=> string(0) “” [“value”]=> bool(false) } 3

    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>'; 
           }
                
    ?>
  • Hi @Cyril

    Perhaps this feature request needs to be explained in detail. I’ll try my best to recommend a solution.

    Thanks
    E

  • Hi @istrasoft

    Great feedback. Yes. I will look into this and perhaps find a way to create a ‘default’ WP_Query value to solve the issue perfectly.

    I know you can hook into the SQL sort statement and write a CASE where you can define values that don’t exist, but I will need to trial this code before mentioning it.

    Cheers
    E

  • Hi @figureone

    Thanks mate. I really appreciate your help on this one, even though I can’t offer a quick solution.

    Yes, I think the best solution is to offer an option for the field. But perhaps we could do this as a ‘non UI’ option such as a filter for the wysiwyg field.

    Something like:

    
    <?php 
    
    apply_filter('acf/fields/wysiwyg/strip_slashes', 'my_wysiwyg_strip_slashes', 10, 1);
    
    function my_wysiwyg_strip_slashes( $strip_slashes )
    {
    	// default is true
    	$strip_slashes = false;
    	
    	return $strip_slashes;
    }
    
    ?>
    

    I’ll add this to the to-do and re-read over this entire thread to make sure I haven’t missed something.

    As for timings, I’m extremely busy for the next 2 weeks, but then I’m going back to full time dev on ACF! So this will definitely be introduced into the core soon.

    Thanks a million
    Cheers
    E

  • 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.

  • Thanks Elliot,
    My question was not ony a display matter. The goal behind these “multiple fields in one” is to build with a few clics a potentially very complex UI, coupled to specific validation rules and treatments.

  • Perfect! I will give it a try. Thanks Elliot!

  • Thanks Nuro. The opening tag was there but I hadn’t copied it in.

    Anyway, I seem to have solved this problem now. I hadn’t switched on debugging mode and when I did a few errors came up – one about automatic feed links and another about how I had enqueued jquery. I’ve sorted these out and now get_field() is working.

    I now have another issue where I can’t add more than one item in my repeater field (which I had been able to before) but if I can’t sort that out I’ll start up another topic.

    Thanks again,
    Elizabeth

  • Hi @elliot and thanks for your information.

    I investigated and here are the results. They may be useful to a future person that has the same issue, or maybe to enhance ACF a bit.

    I switched the field type from True/False to Radio, where I was able to provide two text values ‘yes’ / ‘no’ and defined ‘no’ to be the default value.

    However, the WP_Query still only returned the same, and then it hit me. The problem was not what I thought. Actually, I had already 250 articles, and when adding a new custom field through ACF, unless each article is manually edited and updated, the custom field is not listed at all in the meta data of that article. This does not depend on the actal value or default value of the field.

    So, what would be a nice to have feature is that when adding a new field, having a button or some action link that would allow to set the default value for this new custom field, on all items using this field set, and which have no value for that field at all. Also, adding a little note about this behaviour into the documentation on the queries would help the newbie user to realize how it works.

    Thanks ๐Ÿ™‚

  • In typical fashion, I got there in the end! This is what I ended up using in my template files:

    <?php $image = get_field('field_name'); ?>
    <img src="<?php echo get_template_directory_uri(); ?>/images/loader.gif" alt="" data-src="<?php $image = get_field('field_name'); echo($image['sizes']['custom-size']); ?>" data-src-retina="<?php $image = get_field('field_name'); echo($image['sizes']['custom-size-retina']); ?>" />

    And to the functions.php with these declarations:

    add_image_size( 'custom-size', 300, 300, true ); // Standard pixel density
    add_image_size( 'custom-size-retina', 600, 600, true ); // Double pixel density
  • Yes, sorry for the confusion of my question.
    I thought it served the same code for both, regardless of the multiple-choice factor.
    But his indication was perfect to find the code I needed.
    It had been several times and select the checkbox documentation but I could not understand.
    Now it works perfect for single or multiple value select and checkbox.

    <?php
    if( in_array( 'red', get_field('colors') ) )
    {
       echo '<span class="red"></span>';
    }
    if( in_array( 'green', get_field('colors') ) )
    {
       echo '<span class="green"></span>';
    }
    ?>

    Thanks for your help

  • 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>';
        
    } ?>
  • Hi @digitalquery

    Good news. I have just added and pushed to github an update for the taxonomy field.
    This update contains a new filter allwoing you to customize the args used in the wp_list_categories function.

    You can use it like so:

    
    add_filter('acf/fields/taxonomy/wp_list_categories', 'my_taxonomy_args', 10, 2);
    
    function my_taxonomy_args( $args, $field )
    {
        // do stuff to $args
        return $args;
    }
    
  • Hey @elliot,

    I understand server setups are varied, so lets not waste any more time trying to tackle the problem by identifying which ones have problems with magic quotes.

    Instead, let me show you how ACF doesn’t work on one of the most common server setups, Ubuntu 12.04 LTS (it’s the standard image on Amazon EC2 and linode). Here are some steps I took to reproduce the ACF bug under this setup:

    * I created a test VM environment (Ubuntu 12.04 LTS, PHP 5.3.10, MySQL 5.5.32).
    You can do this easily in vagrant–Ubuntu 12.04 Precise 32bit is the default vagrant box. Instructions on setting up a vagrant virtual machine on your computer is available here:
    http://docs.vagrantup.com/v2/getting-started/

    * I installed a vanilla copy of WordPress 3.6.1 and ACF 4.2.2.

    * I created a new ACF Field Group, and added one Wysiwyg Editor field to the field group. I left all defaults as-is, so the field group appears on all posts on the site.

    * I then edited the sample post included with WordPress (“Hello world!”), and added the following content to the new ACF field:
    Hi! This is ACF content. It just might strip out \ backslashes, which could be \nasty.

    * I then saved the post (by clicking “Update”), and confirmed that the backslashes (“\”) were removed from the above text.

    In short, I think you haven’t heard about this issue from others because the backslash is a lightly used character, and tracing this issue back to ACF is time consuming. But any data loss issue should be treated seriously.

    The easiest solution for you, I think, is to implement another option in the Settings panel for a Wysiwyg field. This setting would simply toggle whether stripslashes_deep() gets called or not. If we do it that way, we don’t have to use get_magic_quotes_gpc() at all, so you shouldn’t get any reports from other users on older PHP setups. This option would default to the current behavior if you wish, so it doesn’t change the default behavior, but it would give me and any others running newer PHP setups the ability to prevent ACF from haphazardly removing backslashes from all ACF wysiwyg content.

    I can provide the pull request with this code, so you don’t have to take extra time writing it. I simply need some sort of assurance that you’ll implement it before I take the time to write the code.

    Cheers,
    -Paul
    PhD Information Science
    College of Education
    University of Hawaii

  • Thanks!

  • Hi @phil.owen

    I think your code is caugin $other_page to be a true|false.
    $other_page = is_page( '$current_user->user_login' );

    Looks like that is a boolean returning function mate, perhaps you meant to write this?

    
    $other_page = $current_user->user_login
    if( is_page( $other_page ) )
    {
        the_field('favourite_movie', $other_page);
    }
    

    2 issues with your code:
    1. quote marks in the is_page function
    2. echo the_field does not need an echo

  • Hi @sirjonathan

    Currently there is no location rule that displays a field group based on it’s children.

    That said, it is quite easy to add your own custom location rules. You can add one for this specific rule following this tutorial:
    http://www.advancedcustomfields.com/resources/tutorials/custom-location-rules/

    Thanks
    E

  • Hi @Cornholio

    Your above loop doesn’t show any relationship to the custom field query…

  • Hi @Rics

    Thanks very much for your help with this issue.
    I have quite a lot on my plate at the moment, but sometime int he future I am looking forward to sitting down and making sure ACF is completely compatible with WPML.

    Thanks
    E

  • Hi @istrasoft

    I would need to run some tests to give you the correct information, but off the top of my head, I’m not 100% sure about the WP_Query / Null issue.

    If you save a post with a checkbox unticked, it will save the value 0.

    I agree that the WP_Query should be able to treat no value as a 0 and order the posts correctly.
    Perhaps this will require some googleing / debugging your SQL result (from the WP_Query object) to find out why the SQL is not returning the correct results

    Good luck
    Cheers
    E

  • This reply has been marked as private.
Viewing 25 results - 20,476 through 20,500 (of 21,337 total)