Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • Hi @lgladdy,

    When I add your code to a Javascript file that loads on the admin pages, I get the following error: ‘ReferenceError: Can’t find variable: acf’, which probably means that it’s running too early.

    When I wrap is with jQuery(function () { ...your code... }, I’m seeing different colors but not the ones that I added to the theme.json file.

    Also: I need this for a colorpicker field on a term page. Should that code work there as well? I suspect it’s only working for pages where the block editor is being loaded.

  • It really depends on you and your browser settings and the browser settings of visitors and what they have done. I have auto play turned off for everything. There is never a time when I want a video to auto pay. Just because a video auto plays for you does not mean it will autoplay for others.

    Autoplay with sound is allowed if:

    • User has interacted with the domain (click, tap, etc.).
    • On desktop, the user’s Media Engagement Index threshold has been crossed, meaning the user has previously played video with sound.
    • The user has added the site to their home screen on mobile or installed the PWA on desktop.

    So really, unless the user takes steps to prevent it then all they need to do is interact with a page. It’s the first visit when the video will not play or subsequent visits if there has never been any interaction on past visits (bounces)

  • Took out $paperCounter for now to try and get 1 random one pulled and have it functioning with the exception of the get_image_with_alt line. Any clue how I could pull 2 randoms, and adjust the line get_image_with_alt to be random? Feel like I am getting close but need a bit of help.

    function getLatestPhotos() {
        if(get_field('photos', 34)) {
            $rows = get_field('photos', 34);
            $row_count = count($rows);
            $i = rand(0, $row_count - 1);
    
            echo $rows[$i]['sub_field_name'];
    
            $latestPhotos .= '<a href="/photos/">';
            $latestPhotos .= get_image_with_alt('cover', get_the_ID(), '');
            $latestPhotos .= '<p>'.$rows[$i]['title'].'</p>';
            $latestPhotos .= '<span>'.$rows[$i]['name'].'</span>';
            $latestPhotos .= '</a>';
    
        }
        return $latestPhotos;
    }
  • @ggus example worked for me, thank you!

    
    <?php
    $template = array(
    	array('acf/custom-block', array('data' => array('text_field'=> 'Test!'))),
    );
    ?>
    
    <div class="example-block">
    	<?php echo '<InnerBlocks template="' . esc_attr(wp_json_encode($template)) . '" />'; ?>
    </div>
    
  • WOW John!!! I had never noticed that 3rd parameter. Indeed that was exactly what I wanted! If only I had your answer yesterday, I wouldn’t have resourced in directly querying the DB…

    $_poster = $wpdb->get_results("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE meta_key = 'movie_poster' AND post_id = {$post->ID};", ARRAY_A)[0]['meta_value'];

    But I’ll update my code as your solution is much more clean! Thanks a lot!

  • Thanks ohn Huebner for your answers.
    I finally find a solution!!!
    The code that worked is this:

    $imgcategory = get_field( 'imagen_de_categoria', 'category_'. $category->term_id ) ;
        echo '<div class="menu_section_parallax" style="background-image: url( ' .$imgcategory. ' )"></div>';

    I´m not sure why it needs the ‘category_’ parameter: if you know it will be very helpfull for the future (my learning future) if you can explain it to me.
    If you can´t, thank you anyway!!

  • While I have you, can you help me sort the floors so highest is first? It is this echo '<ul class="floor tower' . $grandparent_building . '">'; which is the floors. You can see the page here: https://briga.co.il/top-penthouse/briga-blue-bay/choose-apartment-simple/

    Thanks!

  • Thank so much for your answers.

    Anyway, is this correct?

    $imgcategory = get_field('imagen_de_categoria', $category);
    
        echo '<div class="menu_section_parallax" style="background-image: url( '.$imgcategory. ' )"></div>';

    Or this?
    echo '<div class="menu_section_parallax" style="background-image: url( '.get_field('imagen_de_categoria', $category). ' )"></div>';

    Because the images are not showing

  • Somehow I missed your response until now, game-ryo! I see what you did. That’s useful to understand those settings. After reviewing your comment and at least getting my sites to show up in the dropdown (without ajax), I went back to focusing on how to get the ajax set up properly. I returned to another implementation I’d had trouble with previously, from JamesImpression: https://github.com/JamesImpression/acf-multisite-select
    I was able to combine that code’s javascript with my php code based on post_object and finally got it to work!

    The key was to register and enqueue the js (in assets/js/input.js) that calls acf.registerFieldType. It also allows for additional initialization code, but I didn’t need that.

    I’ll try to keep an eye out for alerts if you see this, want to give it a try, and have any questions.

  • I do not know the answer to thing question but I do not think that the 1 site license will work on both.

    This is a user forum. You should contact support here to get an answer https://www.advancedcustomfields.com/contact/

  • The solution that I am posting actually works for me!
    I will post more info about just for anyone that might need it in the future.

    WP All Import cannot import multiply values to a ACF Repeater field if the values are on multiply rows on the xml sheet.

    As the WP All Import authors suggest there is a workaround for that. You can find it here https://www.wpallimport.com/documentation/developers/code-snippets/#append-acf-repeater-data.

    Unfortunately, the above workaround works only if there is one sub-field in the Repeater field.

    So, for my case where the sub-fields are 4, I need to work on another solution.
    The solution is quite simple if you understand the workaround. You need to create a custom field for each ACF Repeater sub-field.

    For my example my 4 subfields are car_make, car_model, car_year and car_type (you need to use field name as shown on ACF on WP admin panel). So I need to create 4 different custom fields, one for each ACF Repeater sub-field.

    I created the my_repeater_data_car_make, my_repeater_data_car_model, my_repeater_data_car_year and my_repeater_data_car_type.

    Then on the import process I used the custom fields option in order to link the data from my xml to the custom fields, please check here https://prnt.sc/19ray48

    Then I just added the below code in the functions editor.

    add_action( 'pmxi_saved_post', 'soflyy_add_data', 10, 3 );
    
    function soflyy_add_data( $id, $xml, $update ) {
      $selector = 'car_make_model_year'; // Parent field name
      $subfield1 = 'car_make'; // The repeating field you want to add the first value to
      $subfield2 = 'car_model'; // The repeating field you want to add the second value to
      $subfield3 = 'car_year'; // The repeating field you want to add the third value to
      $subfield4 = 'car_type'; // The repeating field you want to add the forth value to
    
      if ( $value1 = get_post_meta( $id, 'my_repeater_data_car_make', true )) {
    	  $value2 = get_post_meta( $id, 'my_repeater_data_car_model', true );
    	  $value3 = get_post_meta( $id, 'my_repeater_data_car_year', true );
    	  $value4 = get_post_meta( $id, 'my_repeater_data_car_type', true );
        $row = array( $subfield1 => $value1, $subfield2 => $value2, $subfield3 => $value3, $subfield4 => $value4,  );
        add_row( $selector, $row, $id );
      }
    
      delete_post_meta( $id, 'my_repeater_data_car_make' );
      delete_post_meta( $id, 'my_repeater_data_car_model' );
      delete_post_meta( $id, 'my_repeater_data_car_year' );
      delete_post_meta( $id, 'my_repeater_data_car_type' );
    }

    Run the import and that’s all.

  • The only thing that I can think of here is that the video example is getting the image from the current post and when you’re using a section template you are trying to get the image from a different post than where the image is shown. It may be a case where Elementor is using the wrong post ID, and I don’t know anything about elementor so I can’t tell you how to fix this.

    You should contact elementor support to ask this question and see if they can help you sort it out.

  • You need to get the field “section_settings” and then get the sub field “top_and_bottom_padding” from that. This can be done in a few ways.

    
    // get sections settings as an array
    $section_settings = get_sub_field('section_settings');
    $sectionPadding = $section_settings['top_and_bottom_padding'];
    
    // loop group field
    if (have_rows('section_settings')) {
      // always true for group field
      while (have_rows('section_settings')) {
        // always happens one time for group field
        the_row();
        $sectionPadding = get_sub_field('top_and_bottom_padding');
      }
    }
    
    // get field directly
    // to be honest, I don't know if this will work with nested fields
    // format here is "{$parent_field_name}_{$child_field_name}"
    $sectionPadding = get_sub_field('section_settings_top_and_bottom_padding');
    
  • In addition to the solution I posted above, I came across the problem that the ACF blocks weren’t being stored properly. The ACF field ID’s are required to make sure the entire template is correctly saved into the DB.

    $template = [
        ['acf/acf-block-name', [
            'data' => [
                'repeater_field_name_0_title' => 'Your title here',
                '_repeater_field_name_0_title' => 'field_abc1234567890',
                'repeater_field_name_0_text' => 'Your text here',
                '_repeater_field_name_0_text' => 'field_abc1234567890',
                'repeater_field_name_0_button' => [
                    'title' => 'Button title',
                    'url' => 'Button URL',
                    'target' => 'Button URL'
                ],
                '_repeater_field_name_0_button' => 'field_abc1234567890',
                'repeater_field_name' => 1, // the number of set repeater fields
                '_repeater_field_name' => 'field_abc1234567890'
            ]
        ]],
    ];
  • *Update

    I managed to show only the checkbox with a value matching the ID of the current post with the following code:

    function my_acf_load_field( $field )
    {
        global $post;
    	$post_id = get_the_ID();
        $field['choices'] = array();
        wp_reset_query();
        $query = new WP_Query(array(
            'post_type' => 'projectsoverview',
            'orderby' => 'menu_order',
            'order' => 'ASC',
            'posts_per_page' => -1,
    		'tag' => $post_id
    	));
    	
        foreach($query->posts as $product_id=>$macthed_product){
                $choices[$macthed_product->ID] = $macthed_product->post_title;
        }
    	
        $field['choices'] = array();
    
        if( is_array($choices) )
        {
            foreach( $choices as $key=>$choice )
            {
                $field['choices'][$key] = $choice;
            }
        }
    	
         wp_reset_query();
        return $field;
    	
    }

    Now I am trying to modify the query to only return the checkboxes that are checked. Is there a parameter that I can use for that purpose? Or is there another way?

  • Irene,
    You should definitely just update your site to ACF manually. Your success rate is 100% with this method as opposed to trying to use a very technical approach that requires knowledge of PHP, SQL, and the guts of WordPress. It’s probably not worth the hours of effort to automate the migration when you can just re-enter the values.

    To find the templates where Simple Fields was used you may want to search using terms from here:
    https://simple-fields.com/documentation/api/getting-values/index.html
    This was how most people retrieved simple fields and displayed them on their site. It all depends on what theme you’re using and how many templates there are.

    ACF has similar functionality:
    https://www.advancedcustomfields.com/resources/get_field/
    This is how you retrieve and display custom fields using ACF.

    First you need to create the new fields using ACF and enter the data. Then you would swap one retrieve and display method for the other in your theme’s templates.

    Good luck.
    John

  • I’m sorry, but I can’t really help hare. This requires understanding how both custom field plugins store values. I’m also not familiar with what the OP used to do the conversions. Maybe the OP will reply and give you input.

  • This reply has been marked as private.
  • Hello John or other users who know something about this topic,

    I have some questions regarding the solution described to migrate from Simple Fields to ACF5 fields.
    First of all: does this solution still work?

    Then: a long time ago I worked as a COBOL-programmer and I managed to execute step 1, 2 and 3 myself. But I fear steps 4 and 5 are too complicated for me.
    Is it possible to fill the new ACF5 fields manually? We (a travel agency) use Simple Fields to show extra information for every sample tour we offer (like day-to-day-itinerary, customer review, tips, see e.g. https://www.blinireizen.nl/reizen/georgie-commpleet/, left sidebar). We have 85 tours, with a maximum of 3 fields per tour, so it can be done manually without much effort.

    My last 2 questions concern step 7:
    How do you know in which templates and function.php Simple Fields is used? A simple search doesn’t seem to work.
    How should I call the AFC 5 function? It’s with the same parameters as for Simple Fields?
    An example from single-travel.php (which displays the left sidebar) is:
    $meta_schema = simple_fields_get_post_value($post->ID, “travel schedule”, true);

    Thanks, any help is welcome.

    Irene de Jonge
    Blini Reizen
    Netherlands

  • I am having the same problem where I need to order the terms by php’s natural sort function.

    But through the acf/fields/taxonomy/query filter the only thing you can change is the orderby argument, but you can’t add a custom sort function or better yet sort the result before returning it.

    https://i.imgur.com/hGM2CsU.jpg

  • @warry
    your code helps me a lot!
    it works very well when user tries to add (publish) new post with same value, it gives him the error message that I wrote, the problem happens when the user tries to update other fields at the same post and save, this gives a duplicate error (but in fact it’s not duplicated, the value is exist in only current post, not in the others)

    so, I tried to use get_the_id(); function to ignore current post ID from being checked, but it doesnt work, my code as follows, my field named as “important_estate_clients_mobile” and CPT named “important_clients”:

    // check if mobile field value is already exist
    add_filter('acf/validate_value/name=important_estate_clients_mobile', 'validate_important_clients', 10, 4);
    
    function validate_important_clients($valid, $value, $field, $input) {
      if (!$valid || $value == '') {
        return $valid;
      }
      // query posts for the same value
      // http://codex.wordpress.org/Class_Reference/WP_Query
      global $post; 
       $current_post_id = get_the_id();
      $args = array(
        'post_type' => 'important_clients',  // or your post
        'post__not_in' => array($current_post_id), // do not check this post
        'meta_query' => array(
          array(
            'key' => 'important_estate_clients_mobile',
            'value' => $value
          )
        )
      );
      $query = new WP_Query($args);
      if (count($query->posts)) {
        // found at least one post that
        // already has $value
        $valid = 'رقم العميل هذا مدخل من قبل';
      }
      return $valid;
    } 
  • While I have a good example:

    Table, Block, and Row are options for how the fields are displayed in the admin panel. They are not unique to the ‘flexible content’ type of fields.

    a panel of options for choosing how the custom fields are displayed in the admin panel

    A comparison of these options would be great in the docs. I can find one. I usually just try all three and see which one works best for my specific set of fields. It’s a real challenge to set up the fields in the most compact way – so that my admin page isn’t 10 feet long.


    Here’s a shot of each
    . In this case, it’s a “repeater” field with 4 or so fields in it (and some conditional logic to hide possibly unused fields)

    TABLE

    BLOCK

    ROW

  • I’m finally delving into Gutenberg, and this is a major issue for me as well. As there is no “Gutenberg-style” WYSIWG-type option, it means that if you need to add a WYSIWIG field, you have to repeat all custom theme style programming for compatibility with both Gutenberg and TinyMCE — more than twice the code (since TinyMCE requires more). Are there any solutions in the works for this yet?

Viewing 25 results - 5,476 through 5,500 (of 21,339 total)