Support

Account

Home Forums Search Search Results for 'remove comma'

Search Results for 'remove comma'

reply

  • I think this is closer now:

    // Variables
    $number_of_events = get_field( 'number_of_events' );
    // print_r($number_of_events);
    $terms = get_field('events_category');
    $term_slugs ='';
    foreach ( $terms as $term ):
        $term_slugs .= esc_html( $term->slug ) . ',';
        endforeach;
    $term_slugs = substr($term_slugs, 0, -1); //Removes very last comma.
    // echo $term_slugs;
    // local,virtual,
    
    $args = array(
        'post_type' => 'event',
        'posts_per_page' => $number_of_events,
        // 'event_category' => $term_slugs
        'tax_query' => [
            'taxonomy'         => 'event_category',
            'include_children' => false,
            'field'            => 'name',
            'terms'            => array($term_slugs),
        ],
    );

    but if I added term names I need to quote them as well still. So testing

    
    // Variables
    $number_of_events = get_field( 'number_of_events' );
    // print_r($number_of_events);
    $terms = get_field('events_category');
    $term_slugs ='';
    foreach ( $terms as $term ):
        $term_slugs .= "'" . esc_html( $term->slug ) . "'" . ',';
        endforeach;
    $term_slugs = substr($term_slugs, 0, -1); //Removes very last comma.
    echo $term_slugs;
    // 'local','virtual'
    $args = array(
        'post_type' => 'event',
        'posts_per_page' => $number_of_events,
        // 'event_category' => $term_slugs
        'tax_query' => [
            'taxonomy'         => 'event_category',
            'include_children' => false,
            'field'            => 'name',
            'terms'            => array($term_slugs),
        ],
    );

    Seems though when I use local as category which has only one post and select 4 as the number of posts I still see all four.

  • This has been covered multiple times here. Let me know if none of the existing topics help you https://support.advancedcustomfields.com/forums/search?bbp_search=remove+comma

  • You can find the code that I have added to content section here.

    https://pastebin.com/sPTUXTPw

    Still struggling to remove comma from displayed results. Not sure if I can add something to this code or to CSS for the div to remove a comma from results…

  • Thank you for the quick response John, I really appreciate your help.

    I understand that shortcodes are set-up for simple fields, but it is working in the_content section of a page I have to use.

    The output can be seen here.https://legally-linked.com/groups/clifford-chance/law-firm-technology/

    All the boxes are showing the array via shortcode.

    I have had a look at the format value link you sent, not sure what to add to functions.php

    Something here for shortcodes for select or array fields

    // Render shortcodes in all select values.
    return do_shortcode( $value );
    }

    or something with this

    acf/format_value/type={$type}

    It’s not clear how to remove the commas.

    Best regards

    John

  • How to remove commas on elementor?
    Thanks

  • Thank you @hube2

    I managed to remove the commas, but now it returns the values x 5…

    This is the code:

    `<p class=”shop-link”>
    <?php $values = get_field(‘shop’);

    if ($values) {
    foreach ($values as $value) {
    echo implode(‘<br />’, $values);
    }
    } ?></p>
    `

  • For me, the problem was that the JSON file that I was trying to import had a comma where there wasn’t suppose to be. Specifically it was on the last line of the location array. Here’s an example, notice here that there is a comma at the end of the “value” line:

    
    "location": [
       [
          {
             "param": "post_template",
             "operator": "==",
             "value": "components\/logo-heading-cta.php",
          }
       ]
    ],
    

    When I removed that comma, like this:

    
    "location": [
       [
          {
             "param": "post_template",
             "operator": "==",
             "value": "components\/logo-heading-cta.php"
          }
       ]
    ],
    

    Then the JSON file imported without any problem. I noticed this because my text editor showed that the comma there was a syntax error. It seems JSON is specific about not having a comma after the last item in an array.

    Maybe this will be the solution for anyone else trying to find an answer to this problem.

  • Hello, I’ve fixed @nerd-attack solution for drag&drop also arrays like gallery field etc.

    
    // acf drag n drop flexible layouts between repeaters
    add_action('acf/input/admin_footer', function () {
        ?>
        <script type="text/javascript">
    
            (function($) {
    
                acf.add_action('ready', function($el){
                    $(".values").sortable({
                        connectWith: ".values",
                        start: function(event, ui) {
                            acf.do_action('sortstart', ui.item, ui.placeholder);
                        },
                        stop: function(event, ui) {
                            acf.do_action('sortstop', ui.item, ui.placeholder);
                            $(this).find('.mce-tinymce').each(function() {
                                tinyMCE.execCommand('mceRemoveControl', true, $(this).attr('id'));
                                tinyMCE.execCommand('mceAddControl', true, $(this).attr('id'));
                            });
                        }
                    });
                });
    
                acf.add_action('sortstop', function ($el) {
    
    		// check if the dropped element is within a repeater field
    		if ($($el).parents('.acf-input > .acf-repeater').length) {
    
    			// get column_num from closest acf-row
    			var column_num = $($el).closest('.acf-row').attr('data-id');
    
    			// loop all (input) fields within dropped element and change / fix name
    			$($el).find('[name^="acf[field_"]').each(function () {
    				var field_name = $(this).attr('name');
    				field_name = field_name.match(/\[([a-zA-Z0-9_-]+\])/g); // split name attribute
    				field_name[1] = '[' + column_num + ']'; // set the new row name
    				var new_name = 'acf' + field_name.join('');
    				$(this).attr('name', new_name);
    			});
    
    			// get closest flexible-content-field and loop all layouts within this flexible-content-field
    			$($el).closest('.acf-field.acf-field-flexible-content').find('.acf-input > .acf-flexible-content > .values > .layout').each(function (index) {
    
    				// update order number
    				$(this).find('.acf-fc-layout-order:first').html(index + 1);
    
    				// loop all (input) fields within dropped element and change / fix name
    				$(this).find('[name^="acf[field_"]').each(function () {
    					var field_name = $(this).attr('name');
    					var is_array = field_name.endsWith('[]')
    					field_name = field_name.match(/\[([a-zA-Z0-9_-]+\])/g); // split name attribute
    					var tempIndex = parseInt(field_name[3].match(/([0-9]+)/g)); // hacky code
    					field_name[3] = field_name[3].replace(tempIndex, index); // set the new index
    					var new_name = 'acf' + field_name.join('');
    
    					$(this).attr('name', new_name + is_array ? '[]' : '');
    				});
    
    				// click already selected buttons to trigger conditional logics
    				$(this).find('.acf-button-group label.selected').trigger('click');
    			});
    		}
    	});
    
            })(jQuery);
    
        </script>
        <?php
    });
    
  • hello @lefthookdigital
    i read above thread, i have solution to display fileds along with “_name” and copy it by one click

    demo >> http://prntscr.com/r00zwx

    in functions.php add below code

    
    /*
    |--------------------------------------------------------------------------
    | acf admin slug
    | https://www.advancedcustomfields.com/resources/acf-render_field/
    | https://www.coderomeos.org/select-and-copy-data-to-clipboard-using-jquery
    |--------------------------------------------------------------------------
    */
    add_action('acf/input/admin_footer', 'my_acf_input_admin_footer');
    function my_acf_input_admin_footer() {
    	if ( get_post_type() != 'acf-field-group' ) { ?>
    		<script type="text/javascript">
                jQuery(function($) {
                    $('#wpwrap').each(function(index) {
                        $(this).on('click','.copy-to-clipboard input', function() {
                            $(this).focus();
                            $(this).select();
                            document.execCommand('copy');
                            //$(".copied").text("Copied to clipboard").show().fadeOut(1200);
                        });
                    });
                });
    		</script>
    		<?php
    	}
    }
    
    // Basic
    add_action('acf/prepare_field/type=text', 'show_field_details', 1);
    add_action('acf/prepare_field/type=textarea', 'show_field_details', 1);
    add_action('acf/prepare_field/type=number', 'show_field_details', 1);
    add_action('acf/prepare_field/type=range', 'show_field_details', 1);
    add_action('acf/prepare_field/type=email', 'show_field_details', 1);
    add_action('acf/prepare_field/type=url', 'show_field_details', 1);
    add_action('acf/prepare_field/type=password', 'show_field_details', 1);
    
    // Content
    add_action('acf/prepare_field/type=image', 'show_field_details', 1);
    add_action('acf/prepare_field/type=file', 'show_field_details', 1);
    add_action('acf/prepare_field/type=wysiwyg', 'show_field_details', 1);
    add_action('acf/prepare_field/type=oembed', 'show_field_details', 1);
    add_action('acf/prepare_field/type=gallery', 'show_field_details', 1);
    
    // Choice
    add_action('acf/prepare_field/type=select', 'show_field_details', 1);
    add_action('acf/prepare_field/type=checkbox', 'show_field_details', 1);
    add_action('acf/prepare_field/type=radio', 'show_field_details', 1);
    add_action('acf/prepare_field/type=button_group', 'show_field_details', 1);
    add_action('acf/prepare_field/type=true_false', 'show_field_details', 1);
    
    // Relational
    add_action('acf/prepare_field/type=link', 'show_field_details', 1);
    add_action('acf/prepare_field/type=post_object', 'show_field_details', 1);
    add_action('acf/prepare_field/type=page_link', 'show_field_details', 1);
    add_action('acf/prepare_field/type=relationship', 'show_field_details', 1);
    add_action('acf/prepare_field/type=taxonomy', 'show_field_details', 1);
    add_action('acf/prepare_field/type=user', 'show_field_details', 1);
    
    // jQuery
    add_action('acf/prepare_field/type=google_map', 'show_field_details', 1);
    add_action('acf/prepare_field/type=date_picker', 'show_field_details', 1);
    add_action('acf/prepare_field/type=date_time_picker', 'show_field_details', 1);
    add_action('acf/prepare_field/type=time_picker', 'show_field_details', 1);
    add_action('acf/prepare_field/type=color_picker', 'show_field_details', 1);
    
    // Layout
    //add_action('acf/prepare_field/type=message', 'show_field_details', 1);
    add_action('acf/prepare_field/type=accordion', 'show_field_details', 1);
    //add_action('acf/prepare_field/type=tab', 'show_field_details', 1);
    add_action('acf/prepare_field/type=group', 'show_field_details', 1);
    add_action('acf/prepare_field/type=repeater', 'show_field_details', 1);
    add_action('acf/prepare_field/type=flexible_content', 'show_field_details', 1);
    add_action('acf/prepare_field/type=clone', 'show_field_details', 1);
    
    function show_field_details($field) {
    	$field['label'] .= '<div class="description copy-to-clipboard" style="margin-bottom: 10px; margin-top: 10px;">
    		<input readonly="readonly" type="text" value="'.trim($field['_name']).'" style="color: #0c5460;">
    	</div>';
    	return $field;
    }
    
    add_action('acf/field_group/admin_footer', 'my_acf_field_group_admin_footer');
    function my_acf_field_group_admin_footer() { ?>
    	<script type="text/javascript">
            (function( $ ){
                $('.description.copy-to-clipboard').remove();
            })(jQuery);
    	</script>
    	<?php
    }
    
  • This solution is working for me (ACF 5.8.7):

    // acf drag n drop flexible layouts between repeaters
    add_action('acf/input/admin_footer', function () {
        ?>
        <script type="text/javascript">
    
            (function($) {
    
                acf.add_action('ready', function($el){
                    $(".values").sortable({
                        connectWith: ".values",
                        start: function(event, ui) {
                            acf.do_action('sortstart', ui.item, ui.placeholder);
                        },
                        stop: function(event, ui) {
                            acf.do_action('sortstop', ui.item, ui.placeholder);
                            $(this).find('.mce-tinymce').each(function() {
                                tinyMCE.execCommand('mceRemoveControl', true, $(this).attr('id'));
                                tinyMCE.execCommand('mceAddControl', true, $(this).attr('id'));
                            });
                        }
                    });
                });
    
                acf.add_action('sortstop', function ($el) {
    
                    // check if the dropped element is within a repeater field
                    if($($el).parents('.acf-input > .acf-repeater').length) {
    
                        // get column_num from closest acf-row
                        var column_num = $($el).closest('.acf-row').attr('data-id');
    
                        // loop all (input) fields within dropped element and change / fix name
                        $($el).find('[name^="acf[field_"]').each(function() {
                            var field_name 		= 	$(this).attr('name');
                            field_name          =   field_name.match(/\[([a-zA-Z0-9_-]+\])/g); // split name attribute
                            field_name[1]       =   '[' + column_num + ']'; // set the new row name
                            var new_name        =   'acf' + field_name.join('');
                            $(this).attr('name', new_name);
                        });
    
                        // get closest flexible-content-field and loop all layouts within this flexible-content-field
                        $($el).closest('.acf-field.acf-field-flexible-content').find('.acf-input > .acf-flexible-content > .values > .layout').each(function(index) {
    
                            // update order number
                            $(this).find('.acf-fc-layout-order:first').html(index+1);
    
                            // loop all (input) fields within dropped element and change / fix name
                            $(this).find('[name^="acf[field_"]').each(function() {
                                var field_name 		= 	$(this).attr('name');
                                field_name          =   field_name.match(/\[([a-zA-Z0-9_-]+\])/g); // split name attribute
                                var tempIndex       =   parseInt(field_name[3].match(/([0-9]+)/g)); // hacky code
                                field_name[3]       =   field_name[3].replace(tempIndex, index); // set the new index
                                var new_name        =   'acf' + field_name.join('');
                                $(this).attr('name', new_name);
                            });
    
                            // click already selected buttons to trigger conditional logics
                            $(this).find('.acf-button-group label.selected').trigger('click');
                        });
                    }
                });
    
            })(jQuery);
    
        </script>
        <?php
    });
  • ACF Version 5.8.7

    // acfDragNDropFlexibleLayoutsBetweenRepeaters
    // orginal from https://support.advancedcustomfields.com/forums/topic/drag-flexible-content-layouts-between-parent-repeaters/
    add_action('acf/input/admin_footer', function () {
        ?>
        <script type="text/javascript">
    
            (function($) {
    
                acf.add_action('ready', function($el){
                    $(".values").sortable({
                        connectWith: ".values",
                        start: function(event, ui) {
                            acf.do_action('sortstart', ui.item, ui.placeholder);
                        },
                        stop: function(event, ui) {
                            acf.do_action('sortstop', ui.item, ui.placeholder);
                            $(this).find('.mce-tinymce').each(function() {
                                tinyMCE.execCommand('mceRemoveControl', true, $(this).attr('id'));
                                tinyMCE.execCommand('mceAddControl', true, $(this).attr('id'));
                            });
                        }
                    });
                });
    
                acf.add_action('sortstop', function ($el) {
    
                    // check if the dropped element is within a repeater field
                    if($($el).parents('.acf-input > .acf-repeater').length) {
    
                        // get column_num from closest acf-row
                        var column_num = $($el).closest('.acf-row').attr('data-id');
    
                        // loop all (input) fields within dropped element and change / fix name
                        $($el).find('[name^="acf[field_"]').each(function() {
                            var field_name 		= 	$(this).attr('name');
                            field_name          =   field_name.match(/\[([a-zA-Z0-9_-]+\])/g); // split name attribute
                            field_name[1]       =   '[' + column_num + ']'; // set the new row name
                            var new_name        =   'acf' + field_name.join('');
                            $(this).attr('name', new_name);
                        });
    
                        // get closest flexible-content-field and loop all layouts within this flexible-content-field
                        $($el).closest('.acf-field.acf-field-flexible-content').find('.acf-input > .acf-flexible-content > .values > .layout').each(function(index) {
    
                            // update order number
                            $(this).find('.acf-fc-layout-order:first').html(index+1);
    
                            // loop all (input) fields within dropped element and change / fix name
                            $(this).find('[name^="acf[field_"]').each(function() {
                                var field_name 		= 	$(this).attr('name');
                                field_name          =   field_name.match(/\[([a-zA-Z0-9_-]+\])/g); // split name attribute
                                var tempIndex       =   parseInt(field_name[3].match(/([0-9]+)/g)); // hacky code
                                field_name[3]       =   field_name[3].replace(tempIndex, index); // set the new index
                                var new_name        =   'acf' + field_name.join('');
                                $(this).attr('name', new_name);
                            });
    
                            // click already selected buttons to trigger conditional logics
                            $(this).find('.acf-button-group label.selected').trigger('click');
                        });
                    }
                });
    
            })(jQuery);
    
            function GetSubstringIndex(str, substring, n) {
                var times = 0, index = null;
                while (times < n && index !== -1) {
                    index = str.indexOf(substring, index+1);
                    times++;
                }
                return index;
            }
    
        </script>
        <?php
    });
  • New version, works with 5.8.7:

    // acfDragNDropFlexibleLayoutsBetweenRepeaters
    // orginal from https://support.advancedcustomfields.com/forums/topic/drag-flexible-content-layouts-between-parent-repeaters/
    add_action('acf/input/admin_footer', function () {
        ?>
        <script type="text/javascript">
    
            (function($) {
    
                acf.add_action('ready', function($el){
                    $(".values").sortable({
                        connectWith: ".values",
                        start: function(event, ui) {
                            acf.do_action('sortstart', ui.item, ui.placeholder);
                        },
                        stop: function(event, ui) {
                            acf.do_action('sortstop', ui.item, ui.placeholder);
                            $(this).find('.mce-tinymce').each(function() {
                                tinyMCE.execCommand('mceRemoveControl', true, $(this).attr('id'));
                                tinyMCE.execCommand('mceAddControl', true, $(this).attr('id'));
                            });
                        }
                    });
                });
    
                acf.add_action('sortstop', function ($el) {
    
                    // check if the dropped element is within a repeater field
                    if($($el).parents('.acf-input > .acf-repeater').length) {
    
                        // get column_num from closest acf-row
                        var column_num = $($el).closest('.acf-row').attr('data-id');
    
                        // loop all (input) fields within dropped element and change / fix name
                        $($el).find('[name^="acf[field_"]').each(function() {
                            var field_name 		= 	$(this).attr('name');
                            field_name          =   field_name.match(/\[([a-zA-Z0-9_-]+\])/g); // split name attribute
                            field_name[1]       =   '[' + column_num + ']'; // set the new row name
                            var new_name        =   'acf' + field_name.join('');
                            $(this).attr('name', new_name);
                        });
    
                        // get closest flexible-content-field and loop all layouts within this flexible-content-field
                        $($el).closest('.acf-field.acf-field-flexible-content').find('.acf-input > .acf-flexible-content > .values > .layout').each(function(index) {
    
                            // update order number
                            $(this).find('.acf-fc-layout-order:first').html(index+1);
    
                            // loop all (input) fields within dropped element and change / fix name
                            $(this).find('[name^="acf[field_"]').each(function() {
                                var field_name 		= 	$(this).attr('name');
                                field_name          =   field_name.match(/\[([a-zA-Z0-9_-]+\])/g); // split name attribute
                                var tempIndex       =   parseInt(field_name[3].match(/([0-9]+)/g)); // hacky code
                                field_name[3].replace(tempIndex, tempIndex+1); // set the new index
                                var new_name        =   'acf' + field_name.join('');
                                $(this).attr('name', new_name);
                            });
    
                            // click already selected buttons to trigger conditional logics
                            $(this).find('.acf-button-group label.selected').trigger('click');
                        });
                    }
                });
    
            })(jQuery);
    
            function GetSubstringIndex(str, substring, n) {
                var times = 0, index = null;
                while (times < n && index !== -1) {
                    index = str.indexOf(substring, index+1);
                    times++;
                }
                return index;
            }
    
        </script>
        <?php
    });
  • Thanks John for the reply, however I don’t think I was very clear in my question.
    This is how the whole checkbox selection is set up…

    address1, address2, postcode3 : selectA
    address4, address5, postcode6 : selectB
    address7, address8, postcode9 : selectC

    so the if I check selectA the whole value I get back is “address1, address2, postcode3” rather than an array (I think).
    That’s the part I’d like to remove the commas and replace with a line break.
    Thanks

  • Hi
    Here is my version!

    • Plugin: Advanced Custom Fields PRO Version 5.7.13
    • Field-Structure: ‘repeater’ > ‘flexible_content’

    Big Thanks To Retani

    
    		function acfDragNDropFlexibleLayoutsBetweenRepeaters() {
    ?>
    			<script type="text/javascript">
    				
    				(function($) {
    
    					acf.add_action('ready', function($el){
    						$(".values").sortable({
    							connectWith: ".values",
    							start: function(event, ui) {
    								acf.do_action('sortstart', ui.item, ui.placeholder);
    							},
    							stop: function(event, ui) {
    								acf.do_action('sortstop', ui.item, ui.placeholder);
    								$(this).find('.mce-tinymce').each(function() {
    									tinyMCE.execCommand('mceRemoveControl', true, $(this).attr('id'));
    									tinyMCE.execCommand('mceAddControl', true, $(this).attr('id'));
    								});
    							}
    						});
    					});
    
    					acf.add_action('sortstop', function ($el) {
    
    						// check if the dropped element is within a repeater field
    							if($($el).parents('.acf-input > .acf-repeater').length) {
    
    								// get column_num from closest acf-row
    									var column_num = $($el).closest('.acf-row').attr('data-id');
    
    								// loop all (input) fields within dropped element and change / fix name
    									$($el).find('[name^="acf[field_"]').each(function() {
    										var field_name 		= 	$(this).attr('name');
    										var index_location 	= 	field_name.indexOf(']')+2;
    										var new_name 		= 	field_name.substr(0, index_location) + column_num + field_name.substr(index_location+1);
    										$(this).attr('name', new_name);
    									});
    
    								// get closest flexible-content-field and loop all layouts within this flexible-content-field
    									$($el).closest('.acf-field.acf-field-flexible-content').find('.acf-input > .acf-flexible-content > .values > .layout').each(function(index) {
    
    										// update order number
    											$(this).find('.acf-fc-layout-order:first').html(index+1);
    										
    										// loop all (input) fields within dropped element and change / fix name
    											$(this).find('[name^="acf[field_"]').each(function() {
    												var field_name 		= 	$(this).attr('name');
    												var index_location 	= 	GetSubstringIndex(field_name,']', 3)+2;
    												var new_name 		= 	field_name.substr(0, index_location) + index + field_name.substr(index_location+1);
    												$(this).attr('name', new_name);
    											});
    
    										// click already selected buttons to trigger conditional logics
    											$(this).find('.acf-button-group label.selected').trigger('click');
    									});
    							}
    					});
    
    				})(jQuery); 
    
    				function GetSubstringIndex(str, substring, n) {
    					var times = 0, index = null;
    					while (times < n && index !== -1) {
    						index = str.indexOf(substring, index+1);
    						times++;
    					}
    					return index;
    				}
    
    			</script>
    <?php
    		}
    
    		add_action('acf/input/admin_footer', 'acfDragNDropFlexibleLayoutsBetweenRepeaters');
    
  • Works beautifully! Thank you so much!

    Oddly enough the only thing I was even able to get working at the template level is the below. Kept returning either 0 or “expecting integer, received string” error. Regardless, your fix did the trick globally. Much appreciated.

    // Different versions of a number
    $unformatted = get_field('paid_attendance');
    {
        $integerValue = str_replace(",", "", $unformatted);  // Remove commas from string
        $integerValue = intval($integerValue);               // Convert from string to integer
        $integerValue = number_format($integerValue);        // Apply number format
    
        $floatValue = str_replace(",", "", $unformatted);    // Remove commas from string
        $floatValue = floatval($floatValue);                 // Convert from string to float
        $floatValue = number_format($floatValue, 2);         // Apply number format
    
        echo $integerValue;                                 // Output values
    }
  • I try to remove some lines and done this but got 2 problems.
    1st is no commas and space in between text
    2nd is the last field comes 2 times

    Screenshot: https://prnt.sc/low0fl

    <?php
    	$field_value = get_field('job_qualification');
    	$field_object = get_field_object('job_qualification');
    	$services = $field_object['choices'];
    
    		foreach($services as $value => $label){ 
    
    		if (in_array($value, $field_value)) {
         	$servicesList = "<a target='_blank' href='https://jobsalert.pk/edu/$value'>$label</a>";
    }?>
    <?php echo str_replace(',', ' , ', $servicesList); ?>
    <?php } ?>
  • Thank you so much djcottrell! I’ve put your code at the bottom of the functions.php file of my theme and added the shortcode snippet to the Simple Custom Content field.

    Two issues:

    1. At first, I got an error when I tried to save the revised functions.php file: “syntax error, unexpected T_PUBLIC” – associated with the second line of your code. After a quick search online, it seemed like a good first step to remove the “public ” from that line. After doing that, I was able to save the revised functions.php file.

    2. I then added the shortcode snippet to the Simple Custom Content field. But on the front-end of the site, instead of seeing the values from the checkbox field separated by commas, I now see the word “Array”.

    Any thoughts?

    Thanks again – I can’t tell you how much I appreciate your willingness to help me!

    Frank

  • I just have a quick follow-up question to this original question, and didn’t want to clutter the forum with additional posts. If I should make an additional post, please let me know.

    So everything is working perfectly fine up until this point. I am able to add and remove Users as I please, so long as the User Field is initially populated in the Post.

    However, when using a Multiple Select User Field, if no User is initially populated in the Post, and the following command is run:

    $test = get_field('cb_roster', false, false);
    print_r($test);

    This returns nothing at all. Therefore, if I use something like:
    array_push($test, $current_user);

    Nothing will happen (since it doesn’t exist).

    So, if I run the following:

    $current_user = get_current_user_id();
    $current_user = strval($current_user); //converting to string just in case
    
    $test = get_field('cb_roster', false, false);
    $current_user = array($current_user);
    print_r($test);
    print_r($current_user);
    
    update_field('cb_roster', $current_user);

    And then run:

    $test = get_field('cb_roster', false, false);
    print_r($test);

    I get a blank value (as though it does not exist).

    The output for print_r($current_user) returns:
    Array ( [0] => 24 )

    Which matches the format of the Array if it were populated from the Post.

    Any input is greatly appreciated!

  • Hi,

    I realized that I had to actually change it quite a bit to fit my situation (not just copy&paste as I wrote earlier, sorry!)

    This one works in the following situation:

    repeater “columns” > flexible content “element” > layouts

    Or in words: I have a repeater named “columns” which has one subfield of type “flexible content” named “element” which has several layouts. Each column can have several Elements of different layouts, for example Image, Text-Block, etc.

    Overview of the changes
    – attached “sortstop” and “sortstart” events again
    – changed several selectors
    – re-initialise tinymce after intercolumn drag

    This is not good code, but it works for now. Would be great to have such a thing in ACF.

    
    function my_acf_input_admin_footer() {
    
        ?>
    
            <script type="text/javascript">
            
            (function($) {
    
               acf.add_action('ready', function( $el ){
                   
                   $( ".values" ).sortable({
                     connectWith: ".values",
    
                     start: function(event, ui) {
                        acf.do_action('sortstart', ui.item, ui.placeholder);              
                      },     
    
                     stop: function(event, ui) {
                        acf.do_action('sortstop', ui.item, ui.placeholder);    
    
                        $(this).find('.mce-tinymce').each(function(){
                            tinyMCE.execCommand( 'mceRemoveControl', true, $(this).attr('id') );
                            tinyMCE.execCommand( 'mceAddControl', true, $(this).attr('id') );
                            //$(this).sortable("refresh");
                        });                    
                      },                 
                   })
                   
               });
    
                acf.add_action('sortstop', function ($el) {
                    if ($($el).parents('[data-name="columns"] > .acf-input > .acf-repeater').length) {
                        var column_num = $($el).closest('.acf-row').attr('data-id');
                        $($el).find('[name^="acf[field_"]').each(function(){
                            var field_name = $(this).attr('name');   
                            var index_location = field_name.indexOf(']')+2;
                            var new_name = field_name.substr(0, index_location) + column_num + field_name.substr(index_location+1)
                            $(this).attr('name', new_name);
                        });
                        $($el).closest('[data-name="element"]').find('.acf-input > .acf-flexible-content > .values > .layout').each(function(index){
                            $(this).find('[name^="acf[field_"]').each(function(){
                                var field_name = $(this).attr('name');   
                                var index_location = GetSubstringIndex(field_name,']', 3)+2;
                                var new_name = field_name.substr(0, index_location) + index + field_name.substr(index_location+1);
                                $(this).attr('name', new_name);
                            });
                        });
                    }
                });      
    
            })(jQuery); 
    
            function GetSubstringIndex(str, substring, n) {
                var times = 0, index = null;
    
                while (times < n && index !== -1) {
                    index = str.indexOf(substring, index+1);
                    times++;
                }
    
                return index;
            }  
    
            </script>
    
        <?php
    
    }
    
    add_action('acf/input/admin_footer', 'my_acf_input_admin_footer');
    
  • Hello!
    I have some problem.
    Where can I find it the_field() ? I can’t understand how remove commas 🙁

  • for those who have the same problem. thanks to James, here is the full solution:

        (function($) {
            
            $(document).ready(function(){
    			
    			$("#tagsdiv-knowlendge").appendTo(".acf-field-57bc8db4167d8");
    			$("#tagsdiv-tools").appendTo(".acf-field-57bc8dcc167d9");
    			$("#tagsdiv-materials").appendTo(".acf-field-57bc8de1167da");
    			$("#aboutcontent").append("<div class='clear' style='height:8px;'></div>");    
    
                if( $("#in-category-1").is(':checked') ){
                    $('.acf-field-57bc88444d651 .acf-input').append( $('#postdivrich') );
                }
    			else{
    				$("#acf-group_57bc87aa02bb7").addClass("acf-hidden");
    			}
                
                $('#in-category-1').on("change", function(){
                    if( $(this).is(':checked') ){
                        $('.acf-field-57bc88444d651 .acf-input').append( $('#postdivrich') );
                        tinymce.EditorManager.execCommand('mceRemoveEditor',true, "content");
                        tinymce.EditorManager.execCommand('mceAddEditor',true, "content");
                    } else {
                        $('#post-body-content').append( $('#postdivrich') );
                        tinymce.EditorManager.execCommand('mceRemoveEditor',true, "content");
                        tinymce.EditorManager.execCommand('mceAddEditor',true, "content");
    					$("#acf-group_57bc87aa02bb7").addClass("acf-hidden");
                    }
                });
    			        
            });
            
        })(jQuery); 
  • I took a look at the field groups. The user is not associated with either of the and the fields are not saved to the user in any way, as you said, they are saved to a custom post type.

    The other problem that I see is that on the “Release” post, there can be multiple ring numbers, either a comma separated list of in a repeater. This is going to be a problem to search.

    It would be easier to do the search when viewing the release page/post to search for the found pages/posts.

    
    // get ring numbers
    // $post_id is the post ID of the release page/post 
    // in the 'wglocations' post type
    
    // this first code is for the comma separated list
    $value = get_field('leg_ring_number', $post_id);
    
    // just in case they put spaces after commas, remove them
    $values = str_replace(' ', '', $ring_numbers);
    
    $ring_numbers = explode(',', $value);
    
    // now you have the values in the right format and
    // you can search for matching found numbers
    // the field on the leg_ring_number on post type wglocations
    // can only allow one number
    
    $args = array(
      'post_type' => 'wglocations',
      'posts_per_page' => -1,
      'category_name' => 'wg-finding',
      'meta_query' => array (
        array (
          'key' => 'leg_ring_number',
          'value' => $ring_numbers, // Use the user's 'released' ring numbers
          'compare' => 'IN', // Compare them to any 'found' ring numbers
        )
      )
    );
    $query = new WP_Query ($args);
    // the rest of you code for displaying them continues here
    
  • @acf-support James,

    Here’s the code for the custom fields used on the rep_page post type:

    <?xml version=”1.0″ encoding=”UTF-8″ ?>
    <!– This is a WordPress eXtended RSS file generated by WordPress as an export of your site. –>
    <!– It contains information about your site’s posts, pages, comments, categories, and other content. –>
    <!– You may use this file to transfer that content from one site to another. –>
    <!– This file is not intended to serve as a complete backup of your site. –>

    <!– To import this information into a WordPress site follow these steps: –>
    <!– 1. Log in to that site as an administrator. –>
    <!– 2. Go to Tools: Import in the WordPress admin panel. –>
    <!– 3. Install the “WordPress” importer from the list. –>
    <!– 4. Activate & Run Importer. –>
    <!– 5. Upload this file using the form provided on that page. –>
    <!– 6. You will first be asked to map the authors in this export file to users –>
    <!– on the site. For each author, you may choose to map to an –>
    <!– existing user on the site or to create a new user. –>
    <!– 7. WordPress will then import each of the posts, pages, comments, categories, etc. –>
    <!– contained in this file into your site. –>

    <!– generator=”WordPress/4.4.2″ created=”2016-03-02 12:55″ –>
    <rss version=”2.0″
    xmlns:excerpt=”http://wordpress.org/export/1.1/excerpt/&#8221;
    xmlns:content=”http://purl.org/rss/1.0/modules/wp-content/&#8221;
    xmlns:wfw=”http://wellformedweb.org/CommentAPI/&#8221;
    xmlns:dc=”http://purl.org/dc/elements/1.1/&#8221;
    xmlns:wp=”http://wordpress.org/export/1.1/&#8221;
    >

    <channel>
    <title>IBM Digital Sales</title>
    <link>http://mtev2.w3-969.ibm.com/dswp</link&gt;
    <description>Just another WordPress site</description>
    <pubDate>Wed, 02 Mar 2016 12:55:41 +0000</pubDate>
    <language></language>
    <wp:wxr_version>1.1</wp:wxr_version>
    <wp:base_site_url>http://mtev2.w3-969.ibm.com/dswp/</wp:base_site_url&gt;
    <wp:base_blog_url>http://mtev2.w3-969.ibm.com/dswp</wp:base_blog_url&gt;
    <wp:author><wp:author_id>1</wp:author_id><wp:author_login>admin</wp:author_login><wp:author_email>[email protected]</wp:author_email><wp:author_display_name><![CDATA[admin]]></wp:author_display_name><wp:author_first_name><![CDATA[Marc]]></wp:author_first_name><wp:author_last_name><![CDATA[Getter]]></wp:author_last_name></wp:author>
    <item>
    <title>Rep Page</title>
    <link>http://mtev2.w3-969.ibm.com/dswp</link&gt;
    <pubDate>Fri, 26 Feb 2016 14:50:53 +0000</pubDate>
    <dc:creator>admin</dc:creator>
    <guid isPermaLink=”false”>http://127.0.0.1:8888/Wordpress/?post_type=acf&p=31873</guid&gt;
    <wp:post_id>31873</wp:post_id>
    <wp:post_date>2016-02-26 14:50:53</wp:post_date>
    <wp:post_date_gmt>2016-02-26 14:50:53</wp:post_date_gmt>
    <wp:comment_status>closed</wp:comment_status>
    <wp:ping_status>closed</wp:ping_status>
    <wp:post_name>acf_rep-page</wp:post_name>
    <wp:status>publish</wp:status>
    <wp:post_parent>0</wp:post_parent>
    <wp:menu_order>0</wp:menu_order>
    <wp:post_type>acf</wp:post_type>
    <wp:post_password></wp:post_password>
    <wp:postmeta>
    <wp:meta_key>_edit_last</wp:meta_key>
    <wp:meta_value><![CDATA[1]]></wp:meta_value>
    </wp:postmeta>
    <wp:postmeta>
    <wp:meta_key>field_56d065540d115</wp:meta_key>
    <wp:meta_value><![CDATA[a:14:{s:3:”key”;s:19:”field_56d065540d115″;s:5:”label”;s:5:”eMail”;s:4:”name”;s:5:”email”;s:4:”type”;s:4:”text”;s:12:”instructions”;s:0:””;s:8:”required”;s:1:”1″;s:13:”default_value”;s:0:””;s:11:”placeholder”;s:0:””;s:7:”prepend”;s:0:””;s:6:”append”;s:0:””;s:10:”formatting”;s:4:”html”;s:9:”maxlength”;s:0:””;s:17:”conditional_logic”;a:3:{s:6:”status”;s:1:”0″;s:5:”rules”;a:1:{i:0;a:3:{s:5:”field”;s:4:”null”;s:8:”operator”;s:2:”==”;s:5:”value”;s:0:””;}}s:8:”allorany”;s:3:”all”;}s:8:”order_no”;i:0;}]]></wp:meta_value>
    </wp:postmeta>
    <wp:postmeta>
    <wp:meta_key>field_56d065750d116</wp:meta_key>
    <wp:meta_value><![CDATA[a:13:{s:3:”key”;s:19:”field_56d065750d116″;s:5:”label”;s:6:”Locale”;s:4:”name”;s:6:”locale”;s:4:”type”;s:8:”taxonomy”;s:12:”instructions”;s:0:””;s:8:”required”;s:1:”1″;s:8:”taxonomy”;s:6:”locale”;s:10:”field_type”;s:12:”multi_select”;s:10:”allow_null”;s:1:”0″;s:15:”load_save_terms”;s:1:”1″;s:13:”return_format”;s:2:”id”;s:17:”conditional_logic”;a:3:{s:6:”status”;s:1:”0″;s:5:”rules”;a:1:{i:0;a:3:{s:5:”field”;s:4:”null”;s:8:”operator”;s:2:”==”;s:5:”value”;s:0:””;}}s:8:”allorany”;s:3:”all”;}s:8:”order_no”;i:1;}]]></wp:meta_value>
    </wp:postmeta>
    <wp:postmeta>
    <wp:meta_key>field_56d0661b0d117</wp:meta_key>
    <wp:meta_value><![CDATA[a:14:{s:3:”key”;s:19:”field_56d0661b0d117″;s:5:”label”;s:9:”Page Name”;s:4:”name”;s:9:”page_name”;s:4:”type”;s:4:”text”;s:12:”instructions”;s:0:””;s:8:”required”;s:1:”1″;s:13:”default_value”;s:0:””;s:11:”placeholder”;s:0:””;s:7:”prepend”;s:0:””;s:6:”append”;s:0:””;s:10:”formatting”;s:4:”html”;s:9:”maxlength”;s:0:””;s:17:”conditional_logic”;a:3:{s:6:”status”;s:1:”0″;s:5:”rules”;a:1:{i:0;a:3:{s:5:”field”;s:4:”null”;s:8:”operator”;s:2:”==”;s:5:”value”;s:0:””;}}s:8:”allorany”;s:3:”all”;}s:8:”order_no”;i:2;}]]></wp:meta_value>
    </wp:postmeta>
    <wp:postmeta>
    <wp:meta_key>position</wp:meta_key>
    <wp:meta_value><![CDATA[normal]]></wp:meta_value>
    </wp:postmeta>
    <wp:postmeta>
    <wp:meta_key>layout</wp:meta_key>
    <wp:meta_value><![CDATA[default]]></wp:meta_value>
    </wp:postmeta>
    <wp:postmeta>
    <wp:meta_key>hide_on_screen</wp:meta_key>
    <wp:meta_value><![CDATA[]]></wp:meta_value>
    </wp:postmeta>
    <wp:postmeta>
    <wp:meta_key>field_56d0908f54d73</wp:meta_key>
    <wp:meta_value><![CDATA[a:14:{s:3:”key”;s:19:”field_56d0908f54d73″;s:5:”label”;s:13:”Business Card”;s:4:”name”;s:13:”business_card”;s:4:”type”;s:12:”relationship”;s:12:”instructions”;s:0:””;s:8:”required”;s:1:”0″;s:13:”return_format”;s:2:”id”;s:9:”post_type”;a:1:{i:0;s:14:”content_module”;}s:8:”taxonomy”;a:1:{i:0;s:13:”module_type:4″;}s:7:”filters”;a:1:{i:0;s:6:”search”;}s:15:”result_elements”;a:1:{i:0;s:9:”post_type”;}s:3:”max”;s:0:””;s:17:”conditional_logic”;a:3:{s:6:”status”;s:1:”0″;s:5:”rules”;a:1:{i:0;a:2:{s:5:”field”;s:4:”null”;s:8:”operator”;s:2:”==”;}}s:8:”allorany”;s:3:”all”;}s:8:”order_no”;i:3;}]]></wp:meta_value>
    </wp:postmeta>
    <wp:postmeta>
    <wp:meta_key>rule</wp:meta_key>
    <wp:meta_value><![CDATA[a:5:{s:5:”param”;s:9:”post_type”;s:8:”operator”;s:2:”==”;s:5:”value”;s:8:”rep_page”;s:8:”order_no”;i:0;s:8:”group_no”;i:0;}]]></wp:meta_value>
    </wp:postmeta>
    </item>
    </channel>
    </rss>

    This is the CPT UI export for my content types:

    {“content_module”:{“name”:”content_module”,”label”:”Content Modules”,”singular_label”:”Content Module”,”description”:””,”public”:”true”,”show_ui”:”true”,”show_in_nav_menus”:”true”,”show_in_rest”:”false”,”rest_base”:””,”has_archive”:”false”,”has_archive_string”:””,”exclude_from_search”:”false”,”capability_type”:”post”,”hierarchical”:”true”,”rewrite”:”true”,”rewrite_slug”:””,”rewrite_withfront”:”true”,”query_var”:”true”,”query_var_slug”:””,”menu_position”:”10″,”show_in_menu”:”true”,”show_in_menu_string”:””,”menu_icon”:””,”supports”:[“title”],”taxonomies”:[],”labels”:{“menu_name”:””,”all_items”:””,”add_new”:””,”add_new_item”:””,”edit”:””,”edit_item”:””,”new_item”:””,”view”:””,”view_item”:””,”search_items”:””,”not_found”:””,”not_found_in_trash”:””,”parent”:””},”custom_supports”:””},”rep_page”:{“name”:”rep_page”,”label”:”Rep Pages”,”singular_label”:”Rep Page”,”description”:””,”public”:”true”,”show_ui”:”true”,”show_in_nav_menus”:”true”,”show_in_rest”:”false”,”rest_base”:””,”has_archive”:”false”,”has_archive_string”:””,”exclude_from_search”:”false”,”capability_type”:”post”,”hierarchical”:”false”,”rewrite”:”true”,”rewrite_slug”:””,”rewrite_withfront”:”true”,”query_var”:”true”,”query_var_slug”:””,”menu_position”:”5″,”show_in_menu”:”true”,”show_in_menu_string”:””,”menu_icon”:””,”supports”:[“title”],”taxonomies”:[],”labels”:{“menu_name”:””,”all_items”:””,”add_new”:””,”add_new_item”:””,”edit”:””,”edit_item”:””,”new_item”:””,”view”:””,”view_item”:””,”search_items”:””,”not_found”:””,”not_found_in_trash”:””,”parent”:””},”custom_supports”:””},”account_page”:{“name”:”account_page”,”label”:”Account Pages”,”singular_label”:”Account Page”,”description”:””,”public”:”true”,”show_ui”:”true”,”show_in_nav_menus”:”true”,”show_in_rest”:”false”,”rest_base”:””,”has_archive”:”false”,”has_archive_string”:””,”exclude_from_search”:”false”,”capability_type”:”post”,”hierarchical”:”false”,”rewrite”:”true”,”rewrite_slug”:””,”rewrite_withfront”:”true”,”query_var”:”true”,”query_var_slug”:””,”menu_position”:”10″,”show_in_menu”:”true”,”show_in_menu_string”:””,”menu_icon”:””,”supports”:[“title”],”taxonomies”:[],”labels”:{“menu_name”:””,”all_items”:””,”add_new”:””,”add_new_item”:””,”edit”:””,”edit_item”:””,”new_item”:””,”view”:””,”view_item”:””,”search_items”:””,”not_found”:””,”not_found_in_trash”:””,”parent”:””},”custom_supports”:””}}

    This is the CPT UI export for my taxonomies:

    {“locale”:{“name”:”locale”,”label”:”Locales”,”singular_label”:”Locale”,”description”:””,”hierarchical”:”false”,”show_ui”:”true”,”query_var”:”true”,”query_var_slug”:””,”rewrite”:”true”,”rewrite_slug”:””,”rewrite_withfront”:”1″,”rewrite_hierarchical”:”0″,”show_admin_column”:”false”,”show_in_rest”:”false”,”rest_base”:””,”labels”:{“menu_name”:””,”all_items”:””,”edit_item”:””,”view_item”:””,”update_item”:””,”add_new_item”:””,”new_item_name”:””,”parent_item”:””,”parent_item_colon”:””,”search_items”:””,”popular_items”:””,”separate_items_with_commas”:””,”add_or_remove_items”:””,”choose_from_most_used”:””,”not_found”:””},”object_types”:[“post”]},”module_type”:{“name”:”module_type”,”label”:”Module Types”,”singular_label”:”Module Type”,”description”:””,”hierarchical”:”true”,”show_ui”:”true”,”query_var”:”true”,”query_var_slug”:””,”rewrite”:”true”,”rewrite_slug”:””,”rewrite_withfront”:”1″,”rewrite_hierarchical”:”0″,”show_admin_column”:”false”,”show_in_rest”:”false”,”rest_base”:””,”labels”:{“menu_name”:””,”all_items”:””,”edit_item”:””,”view_item”:””,”update_item”:””,”add_new_item”:””,”new_item_name”:””,”parent_item”:””,”parent_item_colon”:””,”search_items”:””,”popular_items”:””,”separate_items_with_commas”:””,”add_or_remove_items”:””,”choose_from_most_used”:””,”not_found”:””},”object_types”:[“post”]},”account”:{“name”:”account”,”label”:”Accounts”,”singular_label”:”Account”,”description”:””,”hierarchical”:”false”,”show_ui”:”true”,”query_var”:”true”,”query_var_slug”:””,”rewrite”:”true”,”rewrite_slug”:””,”rewrite_withfront”:”1″,”rewrite_hierarchical”:”0″,”show_admin_column”:”false”,”show_in_rest”:”false”,”rest_base”:””,”labels”:{“menu_name”:””,”all_items”:””,”edit_item”:””,”view_item”:””,”update_item”:””,”add_new_item”:””,”new_item_name”:””,”parent_item”:””,”parent_item_colon”:””,”search_items”:””,”popular_items”:””,”separate_items_with_commas”:””,”add_or_remove_items”:””,”choose_from_most_used”:””,”not_found”:””},”object_types”:[“post”]}}

    If you need more, let me know.

    Thanks!

    – Marc

  • Nothing happens on click.

    This is the console on load:

    Consider using 'dppx' units instead of 'dpi', as in CSS 'dpi' means dots-per-CSS-inch, not dots-per-physical-inch, so does not correspond to the actual 'dpi' of a screen. In media query expression: only screen and (-webkit-min-device-pixel-ratio: 2), not all, not all, not all, only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx) post.php?post=28125&action=edit:1
    Consider using 'dppx' units instead of 'dpi', as in CSS 'dpi' means dots-per-CSS-inch, not dots-per-physical-inch, so does not correspond to the actual 'dpi' of a screen. In media query expression: print, not all, (-webkit-min-device-pixel-ratio: 1.25), (min-resolution: 120dpi) post.php?post=28125&action=edit:108
    Uncaught ReferenceError: tinyMCE is not defined post.php?post=28125&action=edit:62
    event.returnValue is deprecated. Please use the standard event.preventDefault() instead.

    Here’s the code causing the TinyMCE error:

                                   <script>
                    jQuery(document).ready( tinymce_excerpt );
                        function tinymce_excerpt() {
                            jQuery("#excerpt").addClass("mceEditor");
                            tinyMCE.execCommand("mceAddControl", false, "excerpt");
                            tinyMCE.onAddEditor.add(function(mgr,ed) {
                                if(ed.id=="excerpt"){
                                    ed.settings.theme_advanced_buttons2 ="";
                                    ed.settings.theme_advanced_buttons1 = "bold,italic,underline,seperator,justifyleft,justifycenter,justifyright,separator,link,unlink,seperator,pastetext,pasteword,removeformat,seperator,undo,redo,seperator,spellchecker,";
                                }
                            });
                        }
            </script>

    I disabled all plugins except ACF and its add-ons to see if that would fix the error, but it did not. Any ideas?

  • Hi @87c

    To get a value for a sub field, please us the get_sub_field function.
    This will solve your issue.

    ALso, please allow an exception in your code to allow for the returned value to be empty. You should wrap your implode code around an if statement to prevent PHP errors.

    Thanks
    E

Viewing 25 results - 26 through 50 (of 51 total)