Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • John,
    thank you for your help, I’ve been visiting the forums often and your posts have been very helpful to me so far.

    I realize that the problem derives from the fact that each repeater subfield can only have a specific set of choices, but I wonder why – hopefully the plugin is extended to support this.. at least target something.

    The function you are describing would be great, as long as I can target what you describe as {DYNAMIC SELECT FIELD NAME}. How do you target this?

    Other than that, populating the field like this is not causing any issues with non-repeater fields, so it might not be a problem here either.

    The way I am using to populate the select field (in non-repeater fields) so it includes the necessary choices, is something like you proposed.. I use a $_GET variable with the post_id and using this I retrieve the manufacturer selection; after that I populate using the prepare_field and the json file – so, when the field is rendered, it already includes the saved model in its choices.

    For the repeater field the closest I can get to is to use the post_id and loop all selected manufacturers and create a choice-list that includes the sum of all manufacturers… which is not what I want.

    The alternative is simply to run a JS function and populate all select fields individually, but this happens client-side and is somewhat heavy.

    So essentially the question is… how can I target individually a select field at a specific repeater row using something like what you proposed – {DYNAMIC SELECT FIELD NAME}?

  • This is not possible without using JS/AJAX. As you have found, acf/prepeare_field only runs once for sub fields of a repeater. I have actually looked into doing this with repeater sub fields and found it impossible.

    The main issue that this will cause is that after a post is saved, since the field actually has no choices any value that the field has will be removed because it cannot be selected. The only thing that you can do to prevent this is to make sure that any already selected values exist as a choice.

    
    add_filter('acf/prepare_field/name={DYNAMIC SELECT FIELD NAME}', 'populate_selected');
    function populate_selected($field) {
      // I don't recall how to get the post ID at the moment
      // you may be able to use global $post
      // or you may need to look at $_GET value
      $post_id = ?? 
      $choices = array();
      if (have_rows('repeater', $post_id)) {
        while (have_rows('repeater', $post_id)) {
          the_row();
          $choices[get_sub_field('select field')] = get_sub_field('select field');
        }
      }
      $field['choices'] = $choices;
      return $field;
    }
    

    In your JS you can get the selected value before populating the field and then after your AJAX and the field is populated you can then reset the selected value.

    Not sure if any of this will help you.

    Let me know if you have questions about targeting each row in your JS to populate the model field based on the manufacturer of that row but basically it looks something like

    
    var other_field = $(field).closest('.acf-row').find('[data-key-"field_XXXXX"] select');
    
  • The problem is that when inserting values in this manor that the acf field key reference is not being added to the database. For each field there is an acf field key reference. This is explained briefly on this page https://www.advancedcustomfields.com/resources/update_field/

    Updating for field name only works for basic text type fields but will not work with complex fields. The field key reference is required for ACF to understand what the field value represents.

    You can insert the values the way you are doing as long as you also insert the field key reference. Let’s say (example) that the field key for “team_member” is “field_XXXXXX”

    
    //...
            'meta_input' => array( 
              'email' => $data['email'], 
              'first_name' => $data['FNAME'], 
              'last_name' => $data['LNAME'], 
              'company' => $company_id, 
              'contact_name' => $data['CONTACTNAM'], 
              'team_member' => $team_member_id,
              '_team_member' => 'field_XXXXXX'
          )
    
  • So I fixed this myself with two new conditions in a custom JS file that uses jquery within the WP admin.

    
    // run the code when the specific tab of the form group is clicked on
    jQuery(document).on('click','*[data-key="field_123456789"]', function(event){
        runCustomCodeFunction();
    });
    // also run my code if the page loads and this tab is visible (it isn't by default as it isn't the first tab)
    if ( jQuery(".acf-field-123456789:visible").length > 0 ) {
        runCustomCodeFunction();
    }
  • (apologies if this is posted twice, got a bug and not sure if it went through)

    Just a quick update, I’ll link to a comment I found by Eliot on github. https://github.com/AdvancedCustomFields/acf/issues/264#issuecomment-629558291

    Basically says that if you use “get_fields” instead of single “get_field” functions, it won’t pass the data because the name of the fields aren’t declared at that moment in the code execution. You can still pass examples without refactoring your code to use “get_field”, but you have to use the field IDs like so and it will work with “get_fields” :

    
    'example'  => [
        'attributes' => [
            'mode' => 'preview',
            'data' => [
                "field_5efb9b4a86e4d" => "Titre gauche",
                "field_5f29ba5f8e2f1" => "h2",
                "field_5efb9b4a86e4f" => "Sous-titre gauche",
                "field_5efb9b4a86e51" => "<p>Mauris turpis risus scelerisque mollis interdum tincidunt lectus parturient nibh</p>",
                "field_5f08b1ab13927" => ["url" => "http://google.com", "target" => "_blank", "title" => "Lien gauche"],
                "field_5f0c252bdce4e" => 0,
                "field_5f29c57dad9dc" => "text-white",
                "field_5f29c59dad9dd" => "opacity-15",
                "field_5f3a04b753a8d" => "Titre droite",
                "field_5f3a04a953a8c" => "h2",
                "field_5f3a04bd53a8e" => "Sous-titre droite",
                "field_5efb9b4a86e52" => "<p>Mauris turpis risus scelerisque mollis interdum tincidunt lectus parturient nibh</p>",
                "field_5f08b24c905b3" => ["url" => "http://google.com", "target" => "_blank", "title" => "Lien gauche"],
                "field_5f0c2543dce4f" => 0,
                "field_5f29c5dbad9de" => "text-white",
                "field_5f29c5ebad9df" => "opacity-15",
                "is_preview" => 1
            ]
        ]
    ]
    
  • Just a quick update, I’ll link to a comment I found by Eliot on github. https://github.com/AdvancedCustomFields/acf/issues/264#issuecomment-629558291

    Basically says that if you use “get_fields” instead of single “get_field” functions, it won’t pass the data because the name of the fields aren’t declared at that moment in the code execution. You can still pass examples without refactoring your code to use “get_field”, but you have to use the field IDs like so and it will work with “get_fields” :

    
    'example'  => [
        'attributes' => [
            'mode' => 'preview',
            'data' => [
                "field_5efb9b4a86e4d" => "Titre gauche",
                "field_5f29ba5f8e2f1" => "h2",
                "field_5efb9b4a86e4f" => "Sous-titre gauche",
                "field_5efb9b4a86e51" => "<p>Mauris turpis risus scelerisque mollis interdum tincidunt lectus parturient nibh</p>",
                "field_5f08b1ab13927" => ["url" => "http://google.com", "target" => "_blank", "title" => "Lien gauche"],
                "field_5f0c252bdce4e" => 0,
                "field_5f29c57dad9dc" => "text-white",
                "field_5f29c59dad9dd" => "opacity-15",
                "field_5f3a04b753a8d" => "Titre droite",
                "field_5f3a04a953a8c" => "h2",
                "field_5f3a04bd53a8e" => "Sous-titre droite",
                "field_5efb9b4a86e52" => "<p>Mauris turpis risus scelerisque mollis interdum tincidunt lectus parturient nibh</p>",
                "field_5f08b24c905b3" => ["url" => "http://google.com", "target" => "_blank", "title" => "Lien gauche"],
                "field_5f0c2543dce4f" => 0,
                "field_5f29c5dbad9de" => "text-white",
                "field_5f29c5ebad9df" => "opacity-15",
                "is_preview" => 1
            ]
        ]
    ]
    
  • This appears to have been resolved in a subsequent update, as both render_callback and render_template work on the acf/init hook using WordPress 5.5 and ACF Pro 5.9.

  • I have the same problem.

    When the second and subsequent posts, the featured image is affected by the size limit of the image field.

    Environment
    – WordPress 5.4.2
    – Advanced Custom Fields PRO 5.9.0
    – macOS Mojave 10.14.6
    – MAMP PRO 5.7
    – Firefox
    I’ve seen it reproduce in Chrome and Safari as well.

    Prerequisites
    – image field: Minimum width: 300px, height: 300px, Maximum width: 300px, height: 300px
    – The featured image I want to register is a different size. This time 1200px * 800px.
    – Added 2 images to Media Library: 300px * 300px, 1200px * 800px

    Point!
    The bug will not be reproduced the first time you register a post.

    Steps to reproduce
    1-1. Create 1st post
    1-2. Add an image to custom field
    1-3. Add a featured image
    1-4. Click publish button
    We won’t reproduce it here.

    2-1. Create 2nd post
    2-2. Add an image to custom field
    2-3. Click to add a featured image, 1200px * 800px, you’ll find the message: “Restricted 1200_800.png
    Image width must not exceed 300px.
    Image height must not exceed 300px.”

    3-1. Create 3rd post
    3-2 Add a featured image
    3-3 Click to add an image to custom field, you’ll find No size limit

    I uploaded video to YouTube.

    Please let me know the solution for this.
    Thank you.

  • I might be a bit off with this, but I ran into what I think is a similar issue. I look for an empty field (video thumbnail in my case), and if it’s empty, I look at another field (a vimeo video ID) and I do a little fetch of some json to grab the thumbnail URL and then save it. This has worked great for simple ACF fields.

    I recently wanted to use this in a Group, and noticed the field wasn’t updating.

    I had a few problems:

    – I was using ‘acf/update_value/name=thumbnail_url’ which will match any field (including subfields it turns out) with that name. Cool for most of my other ACFs where I can just have one filter in functions.php to cover a bunch of different ACF fields where I need this. Not cool for this subfield, as the video ID was also in a subfield, so my function was not finding a video ID.
    – I had no idea how to match a subfield in the “acf/update_value/name=foobar” format (still don’t)
    – I had no idea how to fetch the subfield with the video ID

    This was the original function/filter:

    	// Fetch vimeo thumbnail on save - takes video ID as input
    	function rf_acf_update_vimeo_thumb( $value, $post_id, $field ) {
    		// only set a new value if the field is empty
    		if ( $value == '') {
    			// get video here
    			$vimeo_video_id = get_field('vimeo_video_id');
    			// fetch thumb url(s)
    			$vimeo_meta = file_get_contents("https://vimeo.com/api/v2/video/$vimeo_video_id.json");
    			$vimeo_meta = json_decode($vimeo_meta);
    			$vimeo_thumb = $vimeo_meta[0]->thumbnail_large;
    			// set value
    			$value = $vimeo_thumb;
    			return $value;
    		} else {
    			return $value;
    		}
    	}
    	
    	add_filter('acf/update_value/name=thumbnail_url', 'rf_acf_update_vimeo_thumb', 10, 3);

    So to “fix” this:

    – I opted to give my thumbnail field a new name since I don’t know how to match on a subfield only, so that’s now “wfh_thumbnail_url”.
    – I randomly stumbled on another post in these forums that stated a subfield can be fetched by combining the group’s field name and the subfield name, so my “get_field()” for the video ID which is in the group “page_top” and is named “vimeo_video_id” is fetched with “get_field(‘page_top_vimeo_video_id’);”

    With those two changes, things seem to work well.

    // same, but sub-field
    	// Fetch vimeo thumbnail on save - takes video ID as input
    	function rf_acf_update_vimeo_thumb_alt( $value, $post_id, $field ) {
    		// only set a new value if the field is empty
    		if ( $value == '') {
    			// get video here
    			$vimeo_video_id = get_field('page_top_vimeo_video_id');
    			// fetch thumb url(s)
    			$vimeo_meta = file_get_contents("https://vimeo.com/api/v2/video/$vimeo_video_id.json");
    			$vimeo_meta = json_decode($vimeo_meta);
    			$vimeo_thumb = $vimeo_meta[0]->thumbnail_large;
    			// set value
    			$value = $vimeo_thumb;
    			return $value;
    		} else {
    			return $value;
    		}
    	}
    	add_filter('acf/update_value/name=wfh_thumbnail_url', 'rf_acf_update_vimeo_thumb_alt', 10, 3);

    I do wish I could just match with ‘acf/update_value/name=page_top_wfh_thumbnail_url’…

  • You need to put add_filter() outside of the function

    
    function my_acf_prepare_field( $field ) {
    
        // Lock-in the value "https://instagram.com/".
        if( $field['value'] === 'https://instagram.com/' ) {
            $field['readonly'] = true;
        };
        return $field;
    }
    add_filter('acf/prepare_field/name=instagram', 'my_acf_prepare_field');
    
  • Hello again,

    this error occurs because we are using the plugin “WP All Import Pro” in version 4.6.1. This causes a jquery migrate issue (https://wordpress.org/support/topic/wordpress-5-5-compatibility/). After deactivating wp all import pro everything is working fine and our block types available again.

  • What you want to do is very similar to this https://www.advancedcustomfields.com/resources/querying-relationship-fields 8 ball pool except that you’d be using querying “catalog” based on the taxonomy field and using the term ID value instead of the post ID value.

    I did everything, thanks for help.

  • I can only confirm this issue – I registeres the Restricted block from the docs as well as a minimal block with just an <InnerBlocks /> element, but when I insert them in the editor, I see no editable content area. No errors, no cache issue.

    When I inspect the DOM, this is the HTML that is displayed for this block:

    <div aria-label="Block: Restricted" role="group" id="block-e7e75935-f1de-4cca-82f7-53a85e043e73" class="block-editor-block-list__block wp-block is-selected wp-block" data-block="e7e75935-f1de-4cca-82f7-53a85e043e73" data-type="acf/restricted" data-title="Restricted" tabindex="0"><div class="acf-block-component acf-block-body"><div><div class="acf-block-preview"></div></div></div></div>

  • I also ran into this question and solved it with some modifications to the answer given earlier. Maybe it will help someone.

    function fetch_large_slider($postId) {
    	$slider_images = [];
    	$pid = (empty($postId) ? get_post() : $postId);
    
    	// check if acf is used
    	if (function_exists('get_field')) {
    		if (has_blocks($pid)) {
    			$blocks = parse_blocks( $pid->post_content );
    
    			// run trough acf gutenberg/acf-blocks and find the right one
    			foreach ( $blocks as $block ) {
    				// find all selected images
    				if ($block["blockName"] == 'acf/full-page-slider') {
    					// build new array from found images
    					$image_set = $block["attrs"]["data"]["fullpage_slider_images"];
    					// collect image urls inside an array
    					foreach ($image_set as $imageID) {
    						$slider_images[] = wp_get_attachment_image_src($imageID,'full',false)[0];
    					}
    				} else {
    					continue;
    				}
    			}
    		}
    	}
    	return $slider_images;
    }
  • Hi John, I am adding the following to my theme functions file but not having much luck.

    function my_acf_prepare_field( $field ) {
    
        // Lock-in the value "https://instagram.com/".
        if( $field['value'] === 'https://instagram.com/' ) {
            $field['readonly'] = true;
        };
        return $field;
    add_filter('acf/prepare_field/name=instagram', 'my_acf_prepare_field');
    	}

    Is it because I am using the ACF Frontend plugin?

    Thanks in advance

  • Thanks John, I had wondered if this was the answer to my question in research. So thanks for confirming.

  • My guess is that whatever is causing the AJAX issue with ACF is also interfering in some way with the AJAX request made to perform the plugin update.

  • I’m not sure, but it could have to do with the key=>value pairs of your array.

    You could try 'fields' => array_values($GLOBALS['my_query_filters']),

  • I just did a test. My test site is running only WP and ACF. Everything appears to be in working order. You probably have a conflict somewhere else.

    The usual problem is that the is something preventing the AJAX request from succeeding. You will not usually see these errors if they happen because it will prevent the request from returning the correct value. Any PHP error during the request can cause this.

  • If you sync the groups the site will break because the field keys do not match. This is highly dependent on the type of field in question though. If the fields are for simple text values then you should be okay, this is basically the fields listed under “Basic”

    If you don’t have a lot of content the issue can be fixed by editing every post that uses this component in the admin. In the admin edit ACF will be able to find and populate the values correctly. Then you update and acf will swap the field keys.

    You can also do a find and replace in the postmeta table in the db by finding all occurrences of the incorrect field key in meta_value and replacing it with the correct field key.

  • Hi,

    I can inform you, that the Error Messages are not caused from your Plugin.

    I did overtake a website. I found in the functions a code, which provided an image gallery with “next / prev” Navigation. So every Image has its own URL.

    define('ARBP_VERSION', '0.2');
    define('ARBP_TYPE', 'ar_big_pictures');
    define('ARBP_IMAGE_TYPE', 'ar_biggallery');
    
    add_action('init', 'register_arbp_type');
    //add_image_size(ARBP_IMAGE_TYPE, 930, 523, true); 
    
    add_filter( 'intermediate_image_sizes', function($sizes){
        if (!isset($_REQUEST['post_id'])) { return; }
        
        $type = get_post_type($_REQUEST['post_id']);
        foreach($sizes as $key => $value){
            /*if(($type == ARBP_TYPE  &&  $value != ARBP_IMAGE_TYPE && $value != 'thumbnail')
               || ($type != ARBP_TYPE && $value == ARBP_IMAGE_TYPE)){*/
    	if ($type != ARBP_TYPE && $value == ARBP_IMAGE_TYPE) {
                unset($sizes[$key]);
            }
        }
        return $sizes;
    });
    
     
    function register_arbp_type() {
    	
    	$labels = array(
    		'name' => 'Diashow',
    		'singular_name' => 'Diashow',
    		'add_new' => 'Neu',
    		'add_new_item' => 'Neue Diashow',
    		'edit_item' => 'Bearbeite Diashow',
    		'new_item' => 'Neue Diashow',
    		'all_items' => 'Alle Diashows',
    		'view_item' => 'Diashow betrachten',
    		'search_items' => 'Suche nach Diashows',
    		'not_found' =>  'Keine Diashows gefunden',
    		'not_found_in_trash' => 'Keine Diashows im Papierkorb gefunde', 
    		'parent_item_colon' => '',
    		'menu_name' => 'Diashows'
    	  );
    
    	$args = array(
    		'labels' => $labels,
    		'public' => true,
    		'publicly_queryable' => true,
    		'show_ui' => true, 
    		'show_in_menu' => true, 
    		'query_var' => true,
    		'rewrite' => array( 'slug' => 'diashow' ),
    		'capability_type' => 'post',
    		'has_archive' => true, 
    		'hierarchical' => false,
    		'menu_position' => null,
    		
    		'taxonomies' => array('category'),
    		
    		'supports' => array( 'title', 'editor', 'author', 'comments', 'excerpt', 'thumbnail' )
    	); 
    	
    	register_post_type(ARBP_TYPE , $args );
    }
    
    if (is_admin() && isset($_GET['post_type']) && $_GET['post_type'] == ARBP_TYPE) {
        add_action( 'wp_print_scripts', 'ar_big_picts_de_script', 110 );
    }
    
    function ar_big_picts_de_script() {
        wp_dequeue_script('wp-category-permalink.js');
        wp_deregister_script('wp-category-permalink.js');
    }

    When I delete this Code, the Error Messages disappear.

    Just because I’m corious – do you see where the Problem is?

    Thanks a lot for your Help!

    Best
    Mikkel

  • Hi,

    So i have a repeater inside post-type ‘properties’ that stores Lot No and Auction Date for all the Auctions a property is in.

    When going into an event page, say for 12th August it needs to list all of the properties in this auction in Lot No order.

    When i use WP Query i’m doing it as so:

            function my_posts_where( $where ) {
    
            	$where = str_replace("meta_key = 'auctions_$", "meta_key LIKE 'auctions_%", $where);
    
            	return $where;
            }
    
            add_filter('posts_where', 'my_posts_where');
    
            $args = array (
                'post_type'=>'properties',
                'post_status'=>'publish',
                'posts_per_page'=> 40,
                'paged'=> $paged,
                'suppress_filters' => false,
                'meta_query' => array(
                 'proparray' => array(
                   'key' => 'auctions_$_auction_date',
                   'value' => $today2,
                   'compare' => 'LIKE',
                 ),
                 'lot-nos' => array(
                   'key' => 'auctions_$_lot_no',
                   'type' => 'NUMERIC',
    
                ),
            ),
           'orderby' => array(
              //  'auction-dates' => 'ASC',
                'lot-nos' => 'ASC',
            ),
              );
            $wpb_all_query = new WP_Query($args);

    My problem is that it’s picking up Lot Nos from other rows. So if a property has the following date:

    Auction Date : 7th June 2020
    Lot No: 2
    Auction Date: 12th August 2020
    Lot No: 14

    It is picking up the auction date 12th August 2020, but ordering it as Lot No 2, NOT 14. I need it to match to the specific row of the date in question, then get the Lot No from that row. is this possible?

  • Hi,

    sorry for the late reply.

    This is what I get with (for testing) 1 image:

    Warning: Invalid argument supplied for foreach() in /var/www/html/live/files/plugins/advanced-custom-fields-pro/includes/api/api-helpers.php on line 3213

    array(1) { [0]=> array(24) { ["ID"]=> int(282347) ["id"]=> int(282347) ["title"]=> string(14) "04_Porsche_917" ["filename"]=> string(18) "04_Porsche_917.jpg" ["filesize"]=> int(223682) ["url"]=> string(69) "https://aure3.will-fahren.at/files/uploads/2019/03/04_Porsche_917.jpg" ["link"]=> string(75) "https://aure3.will-fahren.at/autowelt/porsche-917/attachment/04_porsche_917" ["alt"]=> string(0) "" ["author"]=> string(4) "1838" ["description"]=> string(0) "" ["caption"]=> string(183) "Der 917-001 wurde als erstes von insgesamt 25 Exemplaren der Homologationsserie im Frühjahr 1969 aufgebaut und als Gruppe-4-Sportwagen vor dem Porsche Werk 1 in Zuffenhausen gezeigt." ["name"]=> string(14) "04_porsche_917" ["status"]=> string(7) "inherit" ["uploaded_to"]=> int(282339) ["date"]=> string(19) "2019-03-12 08:03:18" ["modified"]=> string(19) "2019-03-12 08:04:52" ["menu_order"]=> int(0) ["mime_type"]=> string(10) "image/jpeg" ["type"]=> string(5) "image" ["subtype"]=> string(4) "jpeg" ["icon"]=> string(65) "https://aure3.will-fahren.at/wp-includes/images/media/default.png" ["width"]=> int(1150) ["height"]=> int(647) ["sizes"]=> array(0) { } } }

    I realized that this error message also appears in the Admin Area right above the Custom Fields.

    Thanks and Greetings
    Mikkel

  • Hi,

    sorry for the late reply.

    This is what I get with (for testing) 1 image:

    Warning: Invalid argument supplied for foreach() in /var/www/html/live/files/plugins/advanced-custom-fields-pro/includes/api/api-helpers.php on line 3213
    array(1) { [0]=> array(24) { ["ID"]=> int(282347) ["id"]=> int(282347) ["title"]=> string(14) "04_Porsche_917" ["filename"]=> string(18) "04_Porsche_917.jpg" ["filesize"]=> int(223682) ["url"]=> string(69) "https://aure3.will-fahren.at/files/uploads/2019/03/04_Porsche_917.jpg" ["link"]=> string(75) "https://aure3.will-fahren.at/autowelt/porsche-917/attachment/04_porsche_917" ["alt"]=> string(0) "" ["author"]=> string(4) "1838" ["description"]=> string(0) "" ["caption"]=> string(183) "Der 917-001 wurde als erstes von insgesamt 25 Exemplaren der Homologationsserie im Frühjahr 1969 aufgebaut und als Gruppe-4-Sportwagen vor dem Porsche Werk 1 in Zuffenhausen gezeigt." ["name"]=> string(14) "04_porsche_917" ["status"]=> string(7) "inherit" ["uploaded_to"]=> int(282339) ["date"]=> string(19) "2019-03-12 08:03:18" ["modified"]=> string(19) "2019-03-12 08:04:52" ["menu_order"]=> int(0) ["mime_type"]=> string(10) "image/jpeg" ["type"]=> string(5) "image" ["subtype"]=> string(4) "jpeg" ["icon"]=> string(65) "https://aure3.will-fahren.at/wp-includes/images/media/default.png" ["width"]=> int(1150) ["height"]=> int(647) ["sizes"]=> array(0) { } } }

    I realized that this error message also appears in the Admin Area right above the Custom Fields.

    Thanks and Greetings
    Mikkel

  • Or how to showing only one more
    i need one more somone can help me?

    Thanks

Viewing 25 results - 6,526 through 6,550 (of 21,339 total)