Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • I can confirm that 5.1.7.1 is working fine.

    The issue is still present in 5.2.0.

    Besides downgrading the plugin version, another workaround is to toggle the conditional to show the required field with the error message and fill it with something. Then toggle back the conditional to what it was before. Now when you submit there won’t be any error message, since all required fields have been filled out regardless of conditional state.

  • what is the value of screening_0_date?

    if you dont filter/compare you should get it like that

    <?php 
    $your_date = get_field('screening_0_date');
    //variable like in array (if array has a <h1>titel</h1> it shows you the value as it is at "code-editor")
    echo '<pre>';
    echo htmlspecialchars(print_r($your_date,true));
    echo '</pre>'; 
    ?>
  • <?php
    $count = 0;
    $your_repeater = get_field('your_repeater');
    if($your_repeater){
       while( have_rows('your_repeater') ): the_row();
       $count++;
       $my_field = get_sub_field('my_field');
       if ($count == 1) {
          echo '<div class="image1">'.$my_field.'</div>';
       }
       if ($count == 2) {
          echo '<div class="image2">'.$my_field.'</div>';
       }
       if ($count == 3) {
          echo '<div class="image3">'.$my_field.'</div>';
       }
       if ($count == 4) {
          echo '<div class="image4">'.$my_field.'</div>';
       }
       if ($count == 5) {
          echo '<div class="image5">'.$my_field.'</div>';
       }
    endwhile;  
    }
    ?>

    if you need to echo img at different places use a variable instead of echo first. and echo that variable later.

    $image1 = '<div class="image1">'.$my_field.'</div>';
    ...
    echo $image1;

    or you can try to use:

    get_field('repeatername_0_fieldname'); //for first row
    get_field('repeatername_1_fieldname'); //for second row
    ...
  • Dear Elliot, I have a bad news on this.
    since the last update o mqTranslate this warning has appeared

    DEPRECATION NOTICE
    As of February 19th, 2015, mqTranslate has been deprecated in favor of qTranslate X.

    I’ve made some test but unfortunately, WYSIWYG fails again with qTranslate-X and qTranslate-Plus. (it blanks the fields on saving -> data loss).

    Could you have a look? If you need any more information, I am happy to help.
    Many thanks
    M.

  • Hi. Just realised that the above code is incorrect as that doesn’t get the current category’s ID. This should work…

    
    <?php 
    $category = get_category( get_query_var( 'cat' ) );
    $cat_id = $category->cat_ID;
    if(get_field('cat_image', 'category_'. $cat_id .'')) { ?>
    <?php the_field('cat_image', 'category_'. $cat_id .''); ?>
    <?php endif; ?>
    
  • Hi @Carlos

    Thanks for the question, but I’m having difficulty understanding.

    Are you using v5.2.0?

    If you enable the metaboxes via the ‘Screen Options’ tab, do the metaboxes appear?

  • It sounds like this may have been fixed in the latest update. From the changelog:

    Gallery field: Added attachment_fields_to_save filter for 3rd party custom field support

    I haven’t had a chance to test yet though.

  • David,

    For the acf/validate_save_post action this can easily be done, without “hacking”, using the built in edit_form_after_title action and add a hidden input field with the acf[post_id] name.

    The AJAX post on the post edit screen will serialize all acf named inputs, so in this way, you can easily use the post_id in one of your own acf/validate_save_post hooks. 🙂

    
    // acf/validate_save_post
    add_action( 'edit_form_after_title', 'devplus_edit_form_after_title' );
    function devplus_edit_form_after_title(){
    	global $post;
    	if( $post && isset( $post->ID ) ){
    ?>
    	<input type="hidden" name="acf[post_id]" value="<?php echo $post->ID; ?>" />
    <?php
    	}
    }
    

    Happy ACF coding!

    // T

  • did/would this work? :

    <?php 
    $name_of_the_training = get_posts(array(
    	'post_type' => 'training', //search posttypes of this name
    	'meta_query' => array(
    		array(
    		'key' => 'name_of_the_training', // with a custom field of this name (has to be a relationship field!)
    		'value' => '"' . get_the_ID() . '"', // look for post that has this ID  (matches exaclty "123", not just 123. This prevents a match for "1234")
    		'compare' => 'LIKE'
    		)
    	)
    ));
    if ($name_of_the_training ) {
    foreach( $name_of_the_training  as $training){
     echo  "<span>" .get_field('number_of_days', $training->ID). " days</span><br/>";
     echo "<span>" .get_field('price', $training->ID). " euros</span><br/>";
     }
    }
    ?>
  • Thank you for your answer – it gave me some ideas :). Yes, rather “or similar”… As I understand it by using pre_save_post you effectively declare post type before saving anything(in hooked function), so I can’t get_post_type before I have any kind of post and that’s because I have both of my end-froms on pages with custom templates, but I can use is_page to know from which of these pages I get my data. But there is another but – I have WPML installed and more than four languages on my website so solution above will bring me to suicidal thoughts. I was hoping to do this using new_post in acf_form(), but there is this problem with post_title. Back to square one.

    Sorry for my bad english.

  • Hi @Pipoulito

    You will also need to hook into the posts_where filter and add some extra code to allow for the meta_key to match via LIKE.

    Checkout the following doc for more info
    http://www.advancedcustomfields.com/resources/how-to-query-posts-filtered-by-custom-field-values/#example-5

  • Great plugin, +1 for this request too please Elliot.

  • After struggling with this for quite some time, I was able to find a helpful solution on Stack Exchange here http://stackoverflow.com/questions/24879399/wordpress-acf-how-to-add-rows-to-a-repeater-field-attached-to-a-user-via-custom

    I thought I’d go ahead and post the answer here since I’m sure I’m not the only one who has ran into this same issue of trying to add or remove repeater rows.

    I know it may come across as dumbing it down too much, or over explaining it, but hopefully it will help anyone who runs into this same issue. I’m very surprised there isn’t more out there about this, since it seems to be a pretty common thing.

    Here’s the code and then a breakdown of what each piece is.

    $post_ID = 'id_of_post_youre_updating';
    $field_key = 'field_key_youre_updating';
    $value = get_field( $field_key, $post_ID );
    $value = removeElementWithValue($value, 'sub_field', 'find_this_value');
    
    update_field( $field_key, $value, $post_ID);

    $field_key is the ‘field key’ associated to the repeater field you are trying to update.
    If you need help finding the field key, reference ‘Finding the field key’ on this page http://www.advancedcustomfields.com/resources/update_field/

    $value is retrieving the field (based on the $field_key) associated to the ID ($post_ID) of the post you’re trying to update. This value will be stored in an array.

    The next part is where all of the magic happens. Since the repeater field’s information is stored in a multidimensional array, we need to loop through that array and strip out the value you’re wanting to remove. That’s where the removeElementWithValue() function comes in — I’ll explain that in a moment.

    The ‘sub_field’ will be the subfield of the repeater field where the value is stored, and ‘find_this_value’ is the value you’re looking for, to determine which row to remove.

    The ‘update_field’ string, is what will update the repeater field with the new array (created by the removeElementWithValue function)

    Here is the code for the removeElementWithValue function. This function will loop through a multidimensional array, and strip out the value you’ve supplied. This function can be simply included in your functions.php file, without any alteration.

    function removeElementWithValue($array, $key, $value){
         foreach($array as $subKey => $subArray){
              if($subArray[$key] == $value){
                   unset($array[$subKey]);
              }
         }
         return $array;
    }

    As an added bonus, if you would like to ADD a row to a repeater field, all it takes is a small change to the first block of code. Rather than calling the removeElementWithValue function, you’ll change that line of code to…

    $value[] = array('sub_field' => 'value_you_wish_to_add');

    where the ‘value_you_wish_to_add’ is the value you want added to the new row. You can add multiple rows by adding multiple lines.

    $value[] = array('sub_field' => 'value_you_wish_to_add');
    $value[] = array('sub_field' => 'value_you_wish_to_add_2');
    $value[] = array('sub_field' => 'value_you_wish_to_add_3');

    So the final block of code to ADD a row would be

    $post_ID = 'id_of_post_youre_updating';
    $field_key = 'field_key_youre_updating';
    $value = get_field( $field_key, $post_ID );
    $value[] = array('sub_field' => 'value_you_wish_to_add');
    
    update_field( $field_key, $value, $post_ID);

    Hope this helps.

  • The following code checks if the ACF Pro or ACF plugins are not activated.

    /* Checks to see if "is_plugin_active" function exists and if not load the php file that includes that function */
    if ( ! function_exists( 'is_plugin_active' ) ) {
    	include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 
    }
    
    /* Checks to see if the acf pro plugin is not activated  */
    if ( !is_plugin_active('advanced-custom-fields-pro/acf.php') )  {
     /* Do something when not active */
    }
    
    /* Checks to see if the acf plugin is not activated  */
    if ( !is_plugin_active('advanced-custom-fields/acf.php') )  {
      /* Do something when not active */
    }
  • Also might try changing:

    require_once('/acf-pro/acf.php');

    to:
    require_once( plugin_dir_path( dirname(__FILE__) ) . 'acf-pro/acf.php' );

  • The line in question in the unminified code is filters.refresh();
    on line 4527

  • You need to write the logic into your plugin to find out if the plugin is already activated.

    This should get you started:

    /* Checks to see if "is_plugin_active" function exists and if not load the php file that includes that function */
    if ( ! function_exists( 'is_plugin_active' ) ) {
    	include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 
    }
    
    /* Checks to see if the acf pro plugin is activated  */
    if ( !is_plugin_active('advanced-custom-fields-pro/acf.php') )  {
     /* load the plugin and anything else you want to do */
    }
    
    /* Checks to see if the acf plugin is activated  */
    if ( !is_plugin_active('advanced-custom-fields/acf.php') )  {
     /* load the plugin and anything else you want to do */
    }
  • Hi @Elliot Condon

    I wanted to check on this, too. Specifically, I’d like to use a dropdown for a Single select Taxonomy field used on a User form. This request is mostly for added accessibility.

  • @jtotheroc, I believe if you set the minimum number of allowed rows to 1, it will start the user off with that. I use this feature quite a bit and that’s how I got around it.

  • I have the same issue even after updating to ACF PRO 5.2.0.

    I have six custom field groups:

    1. Five set to show if Page Type equals “Front Page”: http://d.pr/i/19Kcj
    2. One set to show if Page Template equals “Custom”: http://d.pr/i/1hAHO

    The json export of the field groups is available here: http://d.pr/f/1deSX+

    To reproduce:

    1. Create a page set to display as the front page in Settings > Reading.
    2. Create a page that uses a page template named “Custom”.
    3. Visit the front page. Confirm all fields are visible, or toggle them on in the Screen Options panel if they are not visible.
    4. Visit the “custom” page. Notice that the fields are not visible. Toggle all fields on in the Screen Options panel and confirm that they’re visible.
    5. Return to the front page. Refresh the page. The custom fields on that page are no longer visible and the screen options have become unchecked.

    Here’s a gif demonstrating the issue: http://d.pr/i/EXi1

    ACF issue

    No errors are reported in the PHP error logs or in the Console.

    ACF PRO 5.1.9.1 and 5.2.0 both display this issue for me. ACF 5.1.8 works fine.

    I should mention that both pages contain repeater/flexible content fields, in case that’s related.

  • Hey Tommy, I’ve got a similar approach with Bedrock but I’m running composer and wpcli tasks automatically in my deploy.rb. Kinda think having to SSH manually goes against the reason for using automated deploys.

    You need gem 'capistrano-composer' in your gemfile (+ run bundle install). Looks like you’re already using the capistrano-wpcli one though?
    So I assume you’ve set the remote url in your stage rb files:
    e.g. set :wpcli_remote_url, 'http://staging.yoursite.com' for staging.rb

    Then you need the WP-cli config in your deploy.rb, e.g:

    
    # WPCLI config
    set :wpcli_local_url, 'http://local.yoursite.com'
    set :wpcli_local_uploads_dir, 'web/app/uploads/'
    set :wpcli_remote_uploads_dir, -> { shared_path.join('web/app/uploads') }
    set :wpcli_rsync_options, '-rlvz -e "ssh -p4444" --stats --delete --delete-after'
    

    Note, I also push uploads and I need a custom port for ssh, not everyone would need that.

    THEN add a task to run sync in your namespace :deploy do

    
      desc 'Keep WP synced'
      task :wp_sync do
        on roles(:db) do
          info "Push local database and uploads"
          within release_path do
            invoke 'wpcli:db:push'
            invoke 'wpcli:rewrite:flush'
            invoke 'wpcli:uploads:rsync:push'
          end
        end
      end
    

    Then (usually) at the end of your deploy namespace, you need to attach the tasks to the Capistrano flow, with after :updated, 'deploy:wp_sync'

    As for your “Invalid post type” error, I can’t help you though. Just tried the same process and mine works. :/

  • Thanks, Elliot. This is helpful. What are the other parameters we can use here? For example, can we target a specific field by name or all fields within a specific repeater?

    To get some insight, here is our current code that works well, but not sure if it is the best way about it. For example, if you decide to change the class names (which you did in a recent update, this approach will break):

    acf.add_action('load', function($el){
              // Loop through each ACF field
              acf.get_fields().each(function(){
    
                // Specific for Repeaters
                var table = $(this).parents('.acf-table-wrap'), // Get the table wrapper for the repeater
                    row = table.parent('.acf-row'), // Get the acf-row containing everything
                    hidden = table.find('[data-name="<?php echo self::UNIQUE_ID_FIELD_NAME; ?>"] input'); // Get the unique_id hidden field
                // Check if the unique_id field has a value
                if(hidden.length != 0 && hidden.val().length != 0){
                  // We are looking at a parent item since the unique_id is set
                  var remove_row = row.find('.acf-repeater-remove-row'),
                      input = $(this).find('.acf-input'), // Get the input wrapper for the field
                      field_name = $(this).data('name'),
                      field_type = $(this).data('type'),
                      field = null,
                      data = null;
    
                  if(field_type == 'wysiwyg'){
                    field = input.find('.acf-editor-wrap');
                    data = field.find('textarea').val();
                  } else {
                    switch(field_name){
                      case '<?php echo self::ACF_TOPIC_TITLE; ?>':
                        field = input.find('input');
                        data = field.val();
                        break;
                    }
                  }
    
                  if(field != null){
                    // Hide the entire WYSIWYG field
                    field.hide();
                    // Hide remove icon/ability
                    remove_row.css('visibility', 'hidden');
                    // Display the data from the WYSIWYG field
                    input.append(data);
                  }
                }
                // End Repeaters
    
              });
            });
  • Okay, I’ve figured this out:

    
    <?php if( $image['caption'] ): ?>
    <div class="caption"><?php echo $image['caption']; ?></div>
    <?php endif; ?>
    
  • For some reason I can’t get this to work, The page is getting created, but I get redirected to a blank page, my current Front End page looks like:

    
    <?php                    
      $args = array(
        'post_id' => 'new_1',
        'field_groups' => array( 357 ),
        'submit_value' => 'Submit Story', 
        'return' => '%post_url%?foo=bar'
       );
    acf_form( $args );
    ?>
    

    And My Functions File:

    
    //ACF FORM ARGUMENT
    function my_pre_save_post( $post_id )
    {
        // check if this is to be a new post
        if( $post_id != 'new_1' )
        {		
    		return $post_id;
    	}
    	
    	// Create a new post
    	$post = array(
    		'post_status'  => 'publish' ,
    		'post_title'  => $_POST['fields']['field_54f5894e01b06'],
    		'post_content'	=>	$_POST['fields']['field_54f5897401b07'],
    		'post_type'  => 'shortstory',
    		'post_parent'   =>  $_POST['fields']['field_54f596ac44e2b']
    	);  
    
    	// insert the post
    	$post_id = wp_insert_post( $post ); 
    	
    	// update $_POST['return']
    	$_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );    
      
    	return $post_id;
    }
    add_filter('acf/pre_save_post' , 'my_pre_save_post' );
    

    Any help would be much appreciated.

Viewing 25 results - 17,101 through 17,125 (of 21,345 total)