Support

Account

Home Forums Search Search Results for 'event date repeater'

Search Results for 'event date repeater'

topic

  • Unread

    How to Target ACF Edit Page?

    We have a PHP snippet that is being deployed using the Woody Snippets plugin. The code works great and does what it needs to do, which is to populate an ACF text field when the ACF form is saved or updated on the backend.

    But, that snippet is set to “run everywhere” because the only other option within Woody Snippets is to add it to a post or page via a shortcode. We don’t know how to add a shortcode (and have it execute) on an ACF/custom post type form on the back-end.

    The question: How could we edit the snippet (below) to only execute when someone is editing our custom post type on the back-end? We need this because running the snippet everywhere is breaking the Elementor editor, so we’re unable to edit the custom post template.

    Hope that makes sense! Here’s our snippet, if it matters:

    
    // This populates and saves search terms for product landing pages based on what lives in the product tables
    
    function save_search_terms( $post_id ) {
        
        $searchterms = array();
        
        if( have_rows('product_table') ):
        while( have_rows('product_table') ) : the_row();
    
        // Loop over sub repeater rows        
    
            if( have_rows('product_table_products') ):
                while( have_rows('product_table_products') ) : the_row();
    
        // Get sub value
        
        foreach( $tempsearchterms as $tempsearchterm );
            $tempsearchterm = get_sub_field('product_table_product');
                $searchterms[] = $tempsearchterm->part_number . " " . $tempsearchterm->product_name . " " . $tempsearchterm->model_type;
        
                endwhile;
            endif;
        endwhile;
    endif;    
        
        // update field
        
        update_field('search_terms', implode(' ', $searchterms) );
    }
    
    add_action('acf/save_post', 'save_search_terms');
    
    ?>
        <style type="text/css">
    
            #search-terms {
            pointer-events: none;
        }
    
        </style>
    
  • Helping

    How to transfer form Gutenberg-Block to another ACF-Field

    Hi

    I have registered an ACF field as a Gutenberg-Block.

    add_action('acf/init', 'my_acf_init');
    function my_acf_init() {  
        if( function_exists('acf_register_block_type') ) {
            acf_register_block_type(array(
                'name'                => 'event-date',
                'title'                => __('Veranstaltungs-Datum'),
                'description'            => __('Veranstaltungs-Datum'),
                'render_template'   => 'block-rendering/events_date.php',
                'icon'                => 'format-image',
                'keywords'            => array( 'Event' ),
                'mode'                 => 'edit',
                'supports'          => array('multiple' => false, 'className' => true ), 
                'post_types' => array('events',),
            ));
     
        }    
    }  

    It is a repeater field with a date picker (and other fields).
    Is there a way to automatically transfer the date from the Gutenberg block to another ACF field (not registered as a block)?

    Thank you all!
    Matthias

  • Solved

    Date Field – change div class based by date

    Hello ,

    In the site that i develop i was try to change a class to a div by the date that choose in the date field in the admin, the page is events page, and i am using with a repeater field, the date field is a sub-field.

    What in the end i want to achieve – When the date is far from the date event or it is the day – add class to a div “webinar-holder”.
    When the date of the event has passed – add class “old-event”

    i was try as follow

    
                            <?php if( $webinarDate <= date('dmY') ) { ?>
                            <div class="webinar-holder old-event">
                             <?php } elseif ( $webinarDate >= date('dmY') ) { ?>
                             <div class="webinar-holder">
                             <?php } ?>
    

    And this is the long code (with the repeater):

    
               <div class="webinars-container">
                <?php if( have_rows('webinars-repeater') ){ ?>
                        <?php while( have_rows('webinars-repeater') ) { the_row();                                           
                            // vars
                            $webinarTitle = get_sub_field('webinar-title');                                          
                            $webinarDate = get_sub_field('webinar-date');                                           
                            $webinarStartTime = get_sub_field('webinar-time-start');                                           
                            $webinarEndTime = get_sub_field('webinar-time-end');                                           
                            $webinarLecturerImg = get_sub_field('webinar-lecturer');                                           
                            $webinarAboutLecturer = get_sub_field('webinar-about-lecturer');                                           
                            $webinarLink = get_sub_field('webinar-link');                                           
                            $webinarLinkText = get_sub_field('webinar-link-text');                                                                                     
                            ?>
                            
                            <?php if( $webinarDate <= date('dmY') ) { ?>
                            <div class="webinar-holder old-event">
                             <?php } elseif ( $webinarDate >= date('dmY') ) { ?>
                             <div class="webinar-holder">
                             <?php } ?>
                               <!-- details -->
                               <div class="webinar-details">
                                   <div class="webinar-subject">
                                      <?php if (get_locale() == 'he_IL')  {  ?>
                                          <div class="title">על מה נדבר?</div>
                                      <?php } elseif (get_locale() == 'en_US') { ?>
                                          <div class="title">What will we talk about?</div>
                                      <?php } ?>      
                                       <?php echo $webinarTitle; ?>
                                   </div>
                                   <div class="webinar-date">
                                      <?php if (get_locale() == 'he_IL')  {  ?>
                                          <div class="title">בתאריך</div>
                                      <?php } elseif (get_locale() == 'en_US') { ?>
                                          <div class="title">Date</div>
                                      <?php } ?>  
                                       <?php echo $webinarDate; ?>
                                   </div>
                                   <div class="webinar-time">
                                      <?php if (get_locale() == 'he_IL')  {  ?>
                                          <div class="title">בין השעות</div>
                                      <?php } elseif (get_locale() == 'en_US') { ?>
                                          <div class="title">Time</div>
                                      <?php } ?>   
                                       <?php echo $webinarStartTime; ?>&nbsp;-&nbsp;<?php echo $webinarEndTime; ?>
                                   </div>
                               </div>
                               <!-- end details -->
                               <div class="webinar-about-lecturer-container">
                                       <div class="lecturer-image">
                                             <img src="<?php echo $webinarLecturerImg['url']; ?>" alt="<?php echo $webinarLecturerImg['alt'] ?>" />
                                       </div>
                                  <div class="about-lecturer-text"><?php echo $webinarAboutLecturer; ?></div>
                                   <a href="<?php echo $webinarLink; ?>" target="_blank" class="webinar-link" rel="nofollow"><?php echo $webinarLinkText; ?></a>
                               </div>
                            </div>
    
                        <?php } ?>
                <?php } ?>     
               </div>
    

    I don’t now what i missed that isn’t working.

    I will very appreciat for every Instruction what to do to fix this….

  • Solving

    Repeater row in WPQuery issue

    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?

  • Unread

    multiple forms in front end user account

    Hi all.

    I’m building a website that is for booking events, the e-commerce platform is woocommerce. I’ve acted an action to add a new page to the user account called family, where I want the user to be able to manage their family members and contact info.

    So far I’ve added the page, created a repeater for user where they can add a family member and fill in that members information, it saves and all works great.

    Now I’d like to add an ACF group before the repeater that has main information such as emergency contact details and next of kin, but I can’t figure out how to display two fields (the group and the repeater) within the one action and only have one save button to save the details to the users account.

    This is what I have so far that works for the repeater, but if anyone could steer me in the right direction as to how to add the group field, it’d be hugely appreciated.

    <?php
      acf_form_head();
      get_header(); 
    ?>
    
    Family
    
    <div class="family-members-form"><?php 
    
     if ( !is_user_logged_in() ){ 
     echo 'You are not logged in. <br /> <a href="' . get_permalink(31) .'">Log In &rarr;</a>';
    
     } else {
    
     $user = wp_get_current_user();
     
    
    $options = array(
      // 'field_groups' => ['group_5cbd99ef0f584'],
      'fields' => ['field_5f24194f719ca'],
      'form_attributes' => array(
        'method' => 'POST',
        'action' => admin_url("admin-post.php"),
      ),
      'html_before_fields' => sprintf(
        '<input type="hidden" name="action" value="adaptiveweb_save_profile_form">
        <input type="hidden" name="user_id" value="user_%s">',
        $user->ID
      ),
      'post_id' => "user_{$user->ID}",
      'form' => true,
      'html_submit_button' => '<button type="submit" class="acf-button button button-primary button-large" value="Update Profile">Update Profile</button>',
    );
    
    acf_form($options);
     }
    
     ?>
     
     </div>
  • Helping

    Query on a repeater date pear (acf)

    I’m struggling with this. I a have list of date (not fixed, I can have as many date as I want) made thanks to the ACF Repeater. In my query, I want to filter by date.

    But, I have to hide some post if the date choosen is not between my 2 date fields (evenement_date_start and evenement_date_end). This is an example of my date list.

    fields

    So if I choose between 01/10/2020 and 20/10/2020, the event should not show up. But right now, it does and I can’t figure out why.

    This is my query args, my date and variable have this format “Ymd” :

        $args[] =
        ['relation' => 'OR',
            ['relation' => 'AND',
                [
                    "key" => "evenements_liste_dates_AAA_evenement_date_start",
                    "compare" => "<=",
                    "type" => 'DATE',
                    "value" => $startDate,
                ],
                [
                    "key" => "evenements_liste_dates_AAA_evenement_date_end",
                    "compare" => ">=",
                    "type" => 'DATE',
                    "value" => $endDate,
                ]
            ],
            ['relation' => 'OR',
                [
                    "key" => "evenements_liste_dates_AAA_evenement_date_start",
                    "compare" => "BETWEEN",
                    "type" => 'DATE',
                    "value" => [$startDate, $endDate],
                ],
                [
                    "key" => "evenements_liste_dates_AAA_evenement_date_end",
                    "compare" => "BETWEEN",
                    "type" => 'DATE',
                    "value" => [$startDate, $endDate],
                ]
            ],
        ];

    And my post where rewriting

    
        add_filter('posts_where', function ($query, WP_Query $wp_query) {
            if(!is_admin() && $wp_query->query_vars['post_type'] == "evenement" && !$wp_query->is_main_query()) {
                $query = str_replace("meta_key = 'evenements_liste_dates_AAA_evenement_date_start'", "meta_key LIKE 'evenements_liste_dates_%_evenement_date_start'", $query);
                $query = str_replace("meta_key = 'evenements_liste_dates_AAA_evenement_date_end'", "meta_key LIKE 'evenements_liste_dates_%_evenement_date_end'", $query);
            }
            return $query;
        }, 10, 2);
  • Helping

    Hide repeated years in ACF with date picker

    Hello,
    I’m having a repeater working as an events list with a date picker field to get the year of the event.

    I managed to sort them by date but, what I would like to achieve is that it only shows once the year if multiple events are happening in the same year.

    Currently:

    2020. Event 1
    2020. Event 2
    2020. Event 3
    2019. Event 4
    2018. Event 5
    2017. Event 6
    2017. Event 7
    2016. Event 8

    What I want:

    2020. Event 1
    Event 2
    Event 3
    2019. Event 4
    2018. Event 5
    2017. Event 6
    Event 7
    2016. Event 8

    Is this possible?
    I know that WordPress native date function shows it repeated years only once unless you echo them.

    Here’s my code:

    <?php
    
                    $repeater = get_field('press');
                    $order = array();
    
                    foreach ($repeater as $i => $row) {
                        $order[$i] = strtotime($row['date']);
                    }
    
                    array_multisort($order, SORT_DESC, $repeater);
    
                    if ($repeater): ?>
    
    				<ol style="list-style-type:none;">
    				    <?php foreach ($repeater as $i => $row): ?>
    				        <li>
    				        <?php echo $row['date']; ?> <a href="<?php echo
                    $row['link']; ?>" target="_blank"><?php echo $row['article']; ?>
    				</a>
    				        </li>
    				<?php endforeach; ?>
    				</ol>
    
    				<?php else:
                        echo 'No press yet!
    ';
                    endif; ?>
  • Unread

    How to retrieve the id row dynamically from repeater

    Hello everyone,

    i was try to retrieve the id row dynamically from repeater (inside costume post type)
    that have 4 fields:

    1.report name
    2.report date
    3.report featerd image (simple image)
    4. report file (this file is pdf)

    So i need to find dynamically the id of the 4 field , Because every file is different file and i output it through Ajax , How do i need to do that ?

    Now the situation is that i get the same pdf report inside 2 cubes in the front-end, i need that for every cube is different pdf.

    For your reply i will very very appreciat
    Thanks in advance.

    Here is my code :

    in Function.php:

    function get_file_pdf_url(){
            $post_id = $_POST['postid'];
            $files = get_field('foa-reports-content-repeater',$post_id);   
            foreach($files as $file){
                $file_url = $file['report-file-download']['url']; 
            }
        echo $file_url;
        die();
    }
    add_action('wp_ajax_nopriv_get_file_pdf_url', 'get_file_pdf_url');
    add_action('wp_ajax_get_file_pdf_url', 'get_file_pdf_url');

    in Javascript file ( i am post it anyway):

      $("a.report-scale").on('click', function(e){
          e.preventDefault(); 
          $('.popup-modal.modal-overlay').addClass('visible');
          /** AJAX **/
           var post_id = $(this).attr('data-postid');
           var data = '';
           data = {
               action: 'get_file_pdf_url', // function to execute
               postid: post_id,// selected category lvl 1 id
           };
          $.post(get_pdf_file.pdf_ajax_url, data, function(response){
              if(response){
                /** $('.popup-modal .content').html(response);**/
                 PDFObject.embed(response, ".popup-modal .content");
              }
          });
      });

    I also succeeded to do var_dump ,and here i need to reach where i mark:

    Array
    (
    [0] => Array
    (
    [report-name] => file name text number 1
    [report-date] => 10/06/2020
    [report-image] => Array
    (
    [ID] => 492
    [id] => 492
    [title] => reportExample
    [filename] => reportExample.jpg
    [filesize] => 81797
    [url] => https://foantisemitism.org/wp-content/uploads/2020/06/reportExample.jpg
    [link] => https://foantisemitism.org/%d7%93%d7%95%d7%97%d7%95%d7%aa/reportexample/
    [alt] => example 1
    [author] => 2
    [description] =>
    [caption] =>
    [name] => reportexample
    [status] => inherit
    [uploaded_to] => 473
    [date] => 2020-06-10 13:22:34
    [modified] => 2020-06-10 13:24:28
    [menu_order] => 0
    [mime_type] => image/jpeg
    [type] => image
    [subtype] => jpeg
    [icon] => https://foantisemitism.org/wp-includes/images/media/default.png
    [width] => 560
    [height] => 470
    [sizes] => Array
    (
    [thumbnail] => https://foantisemitism.org/wp-content/uploads/2020/06/reportExample-150×150.jpg
    [thumbnail-width] => 150
    [thumbnail-height] => 150
    [medium] => https://foantisemitism.org/wp-content/uploads/2020/06/reportExample-300×252.jpg
    [medium-width] => 300
    [medium-height] => 252
    [medium_large] => https://foantisemitism.org/wp-content/uploads/2020/06/reportExample.jpg
    [medium_large-width] => 560
    [medium_large-height] => 470
    [large] => https://foantisemitism.org/wp-content/uploads/2020/06/reportExample.jpg
    [large-width] => 560
    [large-height] => 470
    )

    )

    [report-file-download] => Array
    (
    [ID] => 491
    [id] => 491
    [title] => the-real-name-of-the-file
    [filename] => the-real-name-of-the-file.pdf
    [filesize] => 1280371
    [url] => https://foantisemitism.org/wp-content/uploads/2020/06/the-real-name-of-the-file.pdf
    [link] => https://foantisemitism.org/%d7%93%d7%95%d7%97%d7%95%d7%aa/%d7%94%d7%aa%d7%a0%d7%95%d7%a2%d7%94-%d7%9c%d7%9e%d7%90%d7%91%d7%a7-%d7%91%d7%90%d7%a0%d7%98%d7%99%d7%a9%d7%9e%d7%99%d7%95%d7%aa-%d7%91%d7%a8%d7%a9%d7%aa-%d7%93%d7%95%d7%97-%d7%91%d7%a0%d7%95%d7%a9/
    [alt] =>
    [author] => 2
    [description] =>
    [caption] =>
    [name] => %d7%94%d7%aa%d7%a0%d7%95%d7%a2%d7%94-%d7%9c%d7%9e%d7%90%d7%91%d7%a7-%d7%91%d7%90%d7%a0%d7%98%d7%99%d7%a9%d7%9e%d7%99%d7%95%d7%aa-%d7%91%d7%a8%d7%a9%d7%aa-%d7%93%d7%95%d7%97-%d7%91%d7%a0%d7%95%d7%a9
    [status] => inherit
    [uploaded_to] => 473
    [date] => 2020-06-10 13:19:55
    [modified] => 2020-06-10 13:24:28
    [menu_order] => 0
    [mime_type] => application/pdf
    [type] => application
    [subtype] => pdf
    [icon] => https://foantisemitism.org/wp-includes/images/media/document.png
    )

    )

    [1] => Array
    (
    [report-name] => file name text number 2
    [report-date] => 19/06/2020
    [report-image] => Array
    (
    [ID] => 492
    [id] => 492
    [title] => reportExample
    [filename] => reportExample.jpg
    [filesize] => 81797
    [url] => https://foantisemitism.org/wp-content/uploads/2020/06/reportExample.jpg
    [link] => https://foantisemitism.org/%d7%93%d7%95%d7%97%d7%95%d7%aa/reportexample/
    [alt] => example 1
    [author] => 2
    [description] =>
    [caption] =>
    [name] => reportexample
    [status] => inherit
    [uploaded_to] => 473
    [date] => 2020-06-10 13:22:34
    [modified] => 2020-06-10 13:24:28
    [menu_order] => 0
    [mime_type] => image/jpeg
    [type] => image
    [subtype] => jpeg
    [icon] => https://foantisemitism.org/wp-includes/images/media/default.png
    [width] => 560
    [height] => 470
    [sizes] => Array
    (
    [thumbnail] => https://foantisemitism.org/wp-content/uploads/2020/06/reportExample-150×150.jpg
    [thumbnail-width] => 150
    [thumbnail-height] => 150
    [medium] => https://foantisemitism.org/wp-content/uploads/2020/06/reportExample-300×252.jpg
    [medium-width] => 300
    [medium-height] => 252
    [medium_large] => https://foantisemitism.org/wp-content/uploads/2020/06/reportExample.jpg
    [medium_large-width] => 560
    [medium_large-height] => 470
    [large] => https://foantisemitism.org/wp-content/uploads/2020/06/reportExample.jpg
    [large-width] => 560
    [large-height] => 470
    )

    )

    [report-file-download] => Array
    (
    [ID] => 531
    [id] => 531
    [title] => sample
    [filename] => sample.pdf
    [filesize] => 3028
    [url] => https://foantisemitism.org/wp-content/uploads/2020/06/sample.pdf
    [link] => https://foantisemitism.org/reports/%d7%99%d7%95%d7%a0%d7%99-2020/sample/
    [alt] =>
    [author] => 2
    [description] =>
    [caption] =>
    [name] => sample
    [status] => inherit
    [uploaded_to] => 525
    [date] => 2020-06-25 15:20:34
    [modified] => 2020-06-25 15:22:52
    [menu_order] => 0
    [mime_type] => application/pdf
    [type] => application
    [subtype] => pdf
    [icon] => https://foantisemitism.org/wp-includes/images/media/document.png
    )

    )

    )

  • Solved

    Javascript error when reordering in Post Object Repeater

    We’re seeing a repeated javascript error when we have multiple posts in a Post Object repeater field and a user tries to reposition them by drag and drop. This has been true since at least 5.8.8, but switching to 5.8.12 did not fix it.

    Scenario:
    * ACF Pro Post Object field – https://www.advancedcustomfields.com/resources/post-object/
    * Select Multiple Values: Yes
    * Create an article, add posts to that field, “Update” to save changes
    * Click and drag one post in that field to a different place in the list
    * Javascript error written to console, Update doesn’t save the change

    Mitigations tried and failed:
    * Upgrading to ACF Pro 5.8.12 from 5.8.8
    * Trying with a completely new post
    * Trying in multiple browsers

    Possibly helpful additions:
    * It’s working fine for one of our developers on their local machine, but we can’t figure out why.

    This prevents us from rearranging posts in fields of that type. We can only successfully rearrange by deleting the posts from the field and adding them again in a new order.

    Error in Chrome console (error also confirmed in Firefox):
    acf-input.min.js?ver=5.8.12:4 Uncaught TypeError: Cannot read property ‘element’ of undefined
    at HTMLLIElement.<anonymous> (acf-input.min.js?ver=5.8.12:4)
    at Function.each (load-scripts.php?c=0&load[chunk_0]=jquery-core,jquery-migrate,utils&ver=5.3.2:2)
    at a.fn.init.each (load-scripts.php?c=0&load[chunk_0]=jquery-core,jquery-migrate,utils&ver=5.3.2:2)
    at HTMLUListElement.stop (acf-input.min.js?ver=5.8.12:4)
    at h.<computed>.<computed>._trigger (widget.min.js?ver=1.11.4:11)
    at h.<computed>.<computed>._trigger (sortable.min.js?ver=1.11.4:11)
    at h.<computed>.<computed>.h.isFunction.a.<computed> [as _trigger] (widget.min.js?ver=1.11.4:11)
    at h.<computed>.<computed>._clear (sortable.min.js?ver=1.11.4:11)
    at h.<computed>.<computed>.h.isFunction.a.<computed> [as _clear] (widget.min.js?ver=1.11.4:11)
    at h.<computed>.<computed>._mouseStop (sortable.min.js?ver=1.11.4:11)

    This links to the “.element” part of the following unminified code:
    // multiple
    if( options.multiple ) {

    // vars
    var $ul = $container.find(‘ul’);

    // sortable
    $ul.sortable({
    stop: function( e ) {

    // loop
    $ul.find(‘.select2-selection__choice’).each(function() {

    // vars
    var $option = $( $(this).data(‘data’).element );

    // detach and re-append to end
    $option.detach().appendTo( $select );
    });

    // trigger change on input (JS error if trigger on select)
    $select.trigger(‘change’);
    }
    });

    // on select, move to end
    $select.on(‘select2:select’, this.proxy(function( e ){
    this.getOption( e.params.data.id ).detach().appendTo( this.$el );
    }));
    }

  • Solved

    Repeater Data in Row Instead of Column

    Hey folks,

    Sorry if this question has been asked, I looked but couldn’t find anything.

    What I am trying to accomplish is this …

    – I have a repeater with things such as image, title, textarea, etc. These all showed up on the frontend.
    – I have three items within that repeater and again they all show up, but in a list/column and not in a row. I have tried both with Bootstrap flexbox and also with CSS Grid, but the outcome is the same.
    – I am not an expert when it comes to ACF, so I am thinking it might be me doing something wrong there.
    – My setup: I have a custom template file; assigned a page to that template; then applied the field group to that template.

    Below is the code that I have added to my template file.

    <?php
    
        if (have_rows('event')) :
    
            while (have_rows('event')) : the_row();
    
                if (get_sub_field('event_rsvp_link_or_email') == 'Link') {
                    $rsvp_link = get_sub_field('event_rsvp_link');
                } else {
                    $rsvp_link = 'mailto:' . get_sub_field('event_rsvp_email');
                }
    
        ?>
    
                <div class="wpbf-grid">
                    <div class="wpbf-medium-1-3">
                        <?php
                        $image = get_sub_field('event_image');
                        if (!empty($image)) : ?>
                            <img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
                        <?php endif; ?>
    
                        <h4><?php the_sub_field('event_title'); ?></h4>
                        <p>
                            <?php the_sub_field('event_date'); ?> at
                            <?php the_sub_field('event_start_time'); ?>
    
                            <?php if (get_sub_field('event_end_time')) {
                                echo ' until ';
                                the_sub_field('event_end_time');
                            }
                            ?>
                        </p>
                        <p><?php the_sub_field('event_description'); ?></p>
                        <p><a href="<?php echo $rsvp_link; ?>">RSVP</a></p>
                    </div>
                </div>
    
        <?php endwhile;
    
        else :
    
            echo '<p>Sorry there are no events at this time</p>';
    
        endif;
    
        ?>

    I appreciate any feedback. Cheers =)

  • Unread

    my_query_filters not showing filter results in archive with repeater sub_fields

    my_query_filters not showing filter results in the archive.php with repeater sub_fields. I am getting the value but when trying to filter the post it does not show any result. rest normal fields showing result fine. here is the code i am using in my functions.php:

    // array of filters (field key => field name)
    $GLOBALS[‘my_query_filters’] = array(
    ‘field_5ebae4d1733b7’ => ‘starting_price’,
    ‘field_5eb8f98a60609’ => ‘coupon_start_date’, //Repeater sub_field
    ‘field_5eb8fdc433e09’ => ‘coupon_end_date’, //Repeater sub_field
    ‘field_5eb8fa4deffb6’ => ‘private_coupon’, //Repeater sub_field
    ‘field_5eb8fd31628b2’ => ‘refundable’,
    ‘field_5eb6b8a81305c’ => ‘star_rating’
    );

    // action
    add_action(‘pre_get_posts’, ‘my_pre_get_posts’, 10, 1);

    function my_pre_get_posts( $query ) {

    // bail early if is in admin
    if( is_admin() ) return;

    // bail early if not main query
    // – allows custom code / plugins to continue working
    if( !$query->is_main_query() ) return;

    // get meta query
    $meta_query = $query->get(‘meta_query’);

    // loop over filters
    foreach( $GLOBALS[‘my_query_filters’] as $key => $name ) {

    // continue if not found in url
    if( empty($_GET[ $name ]) ) {

    continue;

    }

    // get the value for this filter
    // eg: http://www.website.com/events?city=melbourne,sydney
    $value = explode(‘,’, $_GET[ $name ]);

    // append meta query
    $meta_query[] = array(
    ‘key’ => $name,
    ‘value’ => $value,
    ‘compare’ => ‘LIKE’,
    );

    }

    // update meta query
    $query->set(‘meta_query’, $meta_query);

    }

  • Unread

    Remove Expired (DATEPICKER) Row

    Hi there,

    Have been trying to look for a solution to my problem for a couple of days now and unfortunately, am still no nearer to sorting this out…hence the message!

    Am using ACF REPEATER to organise a small EVENT CALENDAR. Have already sorted out the ordering by the dates but now would like to remove/hide the rows when the date has expired.

    Below is the code I’m working with:

    
    <?php 
    		// get repeater field data
    		$repeater = get_field('event_calendar');
    		
    		// vars
    		$order = array();
    		
    		// populate order
    		foreach( $repeater as $i => $row ) {
    			$order[ $i ] = strtotime($row['date']);
    		}
    
    		// multisort
    		array_multisort( $order, SORT_ASC, $repeater );
    		
    		// loop through repeater
    		if( $repeater ):  ?>
             
     		<?php foreach( $repeater as $i => $row ): 
     
     
     		?>
           
    		<div class="calendar-wrapper">
            
            	<div class="event-icon"><img src="<?php echo $row['icon'];?>" alt="ICON"/></div>
            	<div class="event-date"><?php echo $row['date']; ?></div>
            	<div class="event-name"><?php echo $row['event_name']; ?></div>
               <div class="event-venue"><?php echo $row['event_venue']; ?></div>
    			<div class="event-promo"><a href="<?php echo $row['link']; ?>" title="">PROMOTION</a></div> 
           
                
    		</div>	
    		
    		<?php endforeach; ?>
    		<?php endif; ?>
    

    Any help would be greatly appreciated. Have been looking through the forums and can’t seem to find a solution that will work for me. Thanks!

  • Solving

    Bi-Directional Relationship repeater fields

    I am trying to create a Bi Directional Relationship from a ACF Group that contains multiple repeater fields. I have tried John A. Huebner’s Post-2-post and the functions.php code on the ACF site but I don’t think they are designed to work with repeater fields. I have detailed the setup I have below, hoping someone may be able to help 🙂

    I am developing a History site, where I am trying to create relationships between people, places, things events etc. Because there can be many types of relationships and many things related to the same thing (think sibling relationships, builders of a bridge etc) I thought creating a series of repeater selects and repeater Post Objects would be the best way. I have it working well on teh site but I just want the relationships to be update automatically and do away with entering each relationship manually which would be very time consuming and open to errors and omissions.

    Field Group:
    Relationships

    Fields (Type – Repeater):
    – Related People
    – Related Places
    – Related Things…

    Related People Sub Fields:
    – (Type – Select) Relationship: ‘Brother of’, ‘Siling of’, ‘Associate of’ etc
    – (Type – Repeater) Related Person
    – Sub Fields:
    – (Type – Post Object) Related Person

    Related Places Sub Fields:
    – (Type – Select) How Related To Place: ‘Owner of’, ‘Associated with’, ‘Resided at’ etc
    – (Type – Repeater) Related Place
    – Sub Fields:
    – (Type – Post Object) Related Place

    Related Things Sub Fields:
    – (Type – Select) How is Thing related: ‘Associated with’ etc
    – (Type – Repeater) Related Thing
    – Sub Fields:
    – (Type – Post Object) Related Thing

  • Unread

    Bi-Directional Relationship repeater fields

    I am trying to create a Bi Directional Relationship from a ACF Group that contains multiple repeater fields. I have tried John A. Huebner’s Post-2-post and the functions.php code on the ACF site but I don’t think they are designed to work with repeater fields. I have detailed the setup I have below, hoping someone may be able to help 🙂

    I am developing a History site, where I am trying to create relationships between people, places, things events etc. Because there can be many types of relationships and many things related to the same thing (think sibling relationships, builders of a bridge etc) I thought creating a series of repeater selects and repeater Post Objects would be the best way. I have it working well on teh site but I just want the relationships to be update automatically and do away with entering each relationship manually which would be very time consuming and open to errors and omissions.

    Field Group:
    Relationships

    Fields (Type – Repeater):
    – Related People
    – Related Places
    – Related Things…

    Related People Sub Fields:
    – (Type – Select) Relationship: ‘Brother of’, ‘Siling of’, ‘Associate of’ etc
    – (Type – Repeater) Related Person
    – Sub Fields:
    – (Type – Post Object) Related Person

    Related Places Sub Fields:
    – (Type – Select) How Related To Place: ‘Owner of’, ‘Associated with’, ‘Resided at’ etc
    – (Type – Repeater) Related Place
    – Sub Fields:
    – (Type – Post Object) Related Place

    Related Things Sub Fields:
    – (Type – Select) How is Thing related: ‘Associated with’ etc
    – (Type – Repeater) Related Thing
    – Sub Fields:
    – (Type – Post Object) Related Thing

  • Unread

    Update Select in a repeater based on value of other select

    Using the state and city dynamic select fields example (https://github.com/Hube2/acf-dynamic-ajax-select-example/blob/master/dynamic-select-example/my-acf-extension.php), I have an events page (equivalent of city cpt) with a select field (event_type) populated by rows (_event_type) in a repeater (_event_types) on an options page (equivalent of state cpt).

    On Posts, I have a repeater (p_events) with 2 select boxes in 2 columns:

    | p_event_type | p_event |

    I would like to populate p_event with events from the events page depending on the selected event type on p_event_type. p_event_type is populated by rows from the repeater on the options page.

    public function __construct() {
    	// event type field on event 
    	add_action('acf/load_field/key=field_579376941cecc', array($this, 'load_event_type_field_choices'));
    	// event type field on post
    	add_action('acf/load_field/key=field_579376f522130', array($this, 'load_event_type_field_choices'));
    	// event field on post
    	add_action('acf/load_field/key=field_5793770922131', array($this, 'load_event_field_choices'));
    
    	...
    }
    
    public function load_event_type_field_choices($field) {
    	// this function dynamically loads the event type select field choices
    	// from the event types on options page repeater
    			
    	...
    }
    
    public function load_event_field_choices($field) {
    	// this function dynamically loads event field choices
    	// based on the currently saved event type
    			
    	// I only want to do this on Posts
    	global $post;
    	if (!$post || !isset($post->ID) || get_post_type($post->ID) != 'post') {
    		return $field;
    	}
    
    	// get the selected event type by row
    	$repeater = 'p_events';
    	$count = intval(get_post_meta($post->ID, $repeater, true));
    	for ($i=0; $i<$count; $i++) {
                    $event_type = get_post_meta($post->ID, $repeater.'_'.$i.'_'.'p_event_type', true);
                    $events = $this->get_events($event_type);
                    $field['choices'] = $events;
                    return $field;
    	}
    }
  • Unread

    echo key + meta_key (date/time picker) from repeater field

    Okay,
    so basically I created a wordpress calendar, my events are custom post_types.
    Those custom post_types do have a repeater field with date/time picker.
    Now, those events do repeat, that’s why the repeater field, it’s even possible it repeats 2x a day just at a different time.
    I’d like to echo the date + time of each loop.

    This is my code so far:


    for ($d = 0; $d < 6; $d++) {
    $weekday_ts = strtotime(‘tuesday +’ . $d . ‘ day this week ‘ . date(‘Y-m-d H:i’, $first_day_of_month_ts));
    $day_of_the_year = date(“z”, $weekday_ts);
    $beginning_of_day = strtotime(“midnight”, $weekday_ts);
    $end_of_day = strtotime(“tomorrow”, $beginning_of_day) – 1;

    $loop_news = new WP_Query(array(
    ‘posts_per_page’ => -1,
    ‘post_type’ => ‘event_preview’,
    ‘meta_query’ => array(
    array(
    ‘key’ => ‘event_start_date_repeater_$’,
    ‘meta_key’ => ‘event_start_date’,
    ‘value’ => array($beginning_of_day, $end_of_day),
    ‘compare’ => ‘BETWEEN’,
    ),

    )
    ));
    $final_query = new WP_Query();
    $final_query->posts = $loop_news->posts;
    // Recount
    $final_query->post_count = count($final_query->posts);
    $post_count = $final_query->post_count;

    // Convert number into letters
    if ($post_count > 0) {
    $f = new NumberFormatter(“en”, NumberFormatter::SPELLOUT);
    $num_events = $f->format($post_count) . ‘Event’;
    } else {
    $num_events = ”;
    }
    // Current Event Class
    if ($today_ts == $weekday_ts) {
    $current_class = ‘ current’;
    } else {
    $current_class = ”;
    }
    echo ‘<div class=”row”><td class=”‘ . $num_events . ‘ d’ . $day_of_the_year . ‘ ‘ . $current_class . ‘”>’;
    if ($post_count > 0) {
    if ($final_query->have_posts()) :
    while ($final_query->have_posts()) : $final_query->the_post();
    ?>
    <div class=”Title”>
    “>
    <?php the_title(); ?>

    </div>
    <div class=”Details”>

    • <?php the_field(‘details_1’); ?>
    • <?php the_field(‘details_2’); ?>

    </div>
    <?php
    endwhile;
    endif;
    wp_reset_query();
    wp_reset_postdata();
    }
    echo ‘</td></div>’;
    } // end of daily Events

    my Events show on the correct date but how do I echo now this date/time within the repeater field?
    I am kind of lost.

  • Solved

    meta key from repeater field

    Hi,

    I have a custom post_type called ‘event’ which has a repeater field called ‘date’,
    now I am trying to loop them through a calendar which is looping through each day, looking for the dates.

    Now I can easily achieve this with a normal custom field but obviously it will show up only once, how do I loop through with a repeater_field key?

    My code with a normal custom field:

    
    for ($d = 0; $d < 7; $d++) {
    $weekday_ts = strtotime('monday +' . $d . ' day this week ' . date('Y-m-d', $first_day_of_month_ts));
    $day_of_the_year = date("z", $weekday_ts);
    $beginning_of_day = strtotime("midnight", $weekday_ts);
    $end_of_day = strtotime("tomorrow", $beginning_of_day) - 1;
    
    $loop_news = new WP_Query(array(
            'posts_per_page' => -1,
            'post_type' => 'event',
            'meta_query' => array(
               array(
                   'key' => 'date',
                    'value' => array($beginning_of_day, $end_of_day),
                    'compare' => 'BETWEEN',
        ),
     )
     ));
      $final_query = new WP_Query();
    
  • Solving

    Event Date Guidance

    Hello – I’m looking for guidance on how I should setup some data and then display it in two different ways on the front end of my site.

    The data at the moment is very simple – I just want to be able to add Event dates using the date picker and add a simple text description for each event. My initial thought was to use ACF Pro and the Repeater field but it seems like it might not be a good option from a lot of issues I’ve come across in various threads for other folks. Having repeater is not necessary was just a nice visual touch when someone was adding a new event.

    For the two display options I’m going to have simple page that just lists every event that is upcoming or AFTER today’s date. So that when an event is in the past it is not displayed on the page.

    The second display would be in a CTA on the home page and possibly other pages that make it very easy for site visitors to see when the next event date is, just one.

    Can anyone suggest the best performance way to setup my data in ACF and possibly any suggestions for each view? I’ve tried creating a custom shortcode for the second display option but I can’t seem to find anyone that has figured out how to query a repeater sub field (event_date) to get the NEXT event date after today’s date.

    Appreciate any help

  • Solving

    Why is my meta query only looking at the first index of my repeater field

    I am using Advanced Custom Fields Pro and I have a repeater field in my custom post type that has multiple starting dates. So the repeater fields is called date and has starting date so the hierarchy would look like this.

    date
    –startingdate

    So a post can have multiple starting dates. I am using a meta query to get all the posts that start after the date of today.

    $posts = get_posts(array(
        'numberposts'   => $limit,
        'post_type'     => 'events',
        'orderby'           => 'meta_value',
        'meta_query' => array(
             array(
                'key'     => 'date_0_startingdate',
                'value'   => $today,
                'compare' => '>',
            )
        ),
        'order' => $order,
    ));

    But I noticed that it’s only looking at the first index of the repeater field. How can I make sure I looks at all the fields and take the post if there is one date that starts after today.

    If a take a custom post and go to the date repeater field and set it like this

    1. date before today
    2. date after today
    it won’t find the post. But it should because index 2 is a date after today.

    If I set it like this

    1. date after today
    2. date before today
    It will find it.

  • Helping

    Query filtering shows all posts instead specific post

    Hi ACF Team,

    On specific page I’m displaying posts from my CPT („opencourses”). Posts from this specific CPT are grouped by custom taxonomy („kategoria”). And this part works. At the same page I have four different select fields to filter the query. One dropdown is dedicated to filtering by mentioned taxonomy, rest of them are related to repeater subfields. I’ve managed to populate select fields with proper data. And this part works also great.

    What I’m missing is one thing – when I’m filtering my posts, it shows entire group of posts instead THE SPECIFIC post. Hopefully below example will be more descriptive – what I get currently:

    TAXONOMY_CHILD_1
    – Post 1
    – Post 2
    – Post 3
    – Post 4

    What I want to get:

    TAXONOMY_CHILD_1
    – Post 3

    It’s crucial to me just to highlight the specific posts. Taxonomy Childs are in my example types of courses. Inside specific type I have bunch of courses with different timing, location, price, so showing them at the same time is pointless.

    Entire code can be found here:

    
    <?php
    
        $taxonomy = 'typ';
    
            if (is_page(29557) ):
                $childno = '205';
            
            elseif (is_page(29640) ):
                $childno = '206';
    
            endif;										
                                    
        $args = array(
            'child_of'=> $childno,
            'childless' => true  					
        );
    
        $taxonomy_terms = get_terms($taxonomy, $args);
    
        
        if($taxonomy_terms) {
            foreach($taxonomy_terms as $taxonomy_term) {
                
                $taxquery = array('relation' => 'AND');
                $metaquery = array('relation' => 'AND');
    
                if(isset($_GET['obszar']) && $_GET['obszar'] != '')
                {
                    $taxquery[] =  array(
                        'taxonomy' => 'kategoria',
                        'field'    => 'slug',
                        'terms'    => $_GET["obszar"],
                        );
                }
                if(isset($_GET['firma']) && $_GET['firma'] != '')
                {
                    $metaquery[] =  array(
                        'compare' => '=',
                        'key'    => 'terminy_warsztatow_$_firma',
                        'value'    => $_GET["firma"],
                    );
                }
                if(isset($_GET['lokalizacja']) && $_GET['lokalizacja'] != '')
                {
                    $metaquery[] =  array(
                        'compare' => '=',
                        'key'    => 'terminy_warsztatow_$_wojewodztwo',
                        'value'    => $_GET["lokalizacja"],
                    );
                }
                if(isset($_GET['data']) && $_GET['data'] != '')
                {
                    $metaquery[] =  array(
                        'compare' => '=',
                        'key'    => 'terminy_warsztatow_$_data',
                        'value'    => $_GET["data"],
                    );
                }
                
                $args_main_query = array(
                    'post_type' => 'opencourses',
                    "$taxonomy" => $taxonomy_term->slug,
                    'post_status' => 'publish',
                    'posts_per_page' => -1,	
                    'fields' => 'all',
                    'tax_query' => $taxquery,
                    'meta_query' => $metaquery,
                );
    
                $query = new WP_Query( $args_main_query );
            
                if ( $query->have_posts() ) : ?>
    
                <?php $color = get_field('blok_szkoleniowy_kolor', $taxonomy_term); ?>
    
                <div class="term_anchor" id="<?php echo $taxonomy_term->slug; ?>"></div>
                <h4 class="term_blok_szkoleniowy"><span class="spacer" style="background:<?php echo $color; ?>"></span><?php echo $taxonomy_term->name; ?></h4>
    
                    <?php while ( $query->have_posts() ) : $query->the_post(); ?>
    
                    <div class="row">
                        <div class="col-md-12">
                            <div class="coursWrapper">
                        
                                <div class="visibleInfoCourses" style="border-left: 5px solid <?php echo $color; ?>">
                                        <div class="row">
                                            <div class="col-sm-7">
                                                <p><a href="<?php the_permalink() ?>"><?php the_title() ?></a>
                                                <?php if (get_field('nowosc')) : ?><span class="labelItem labeImNew">Nowość</span><?php endif ?>
                                                <?php if (get_field('new_form')) : ?><span class="labelItem labeImNewForm">Nowa formuła</span><?php endif ?>
                                                <?php if (get_field('new_date_info')) : ?><span class="labelItem labeImNewDate">Zmiana terminu</span><?php endif ?>
                                                </p>
                                            </div>
                                            <div class="col-sm-5">
                                                <div class="buttonsHereRight">
                                                    <button class="btnBorderGrey btn-lean-sm">Terminy warsztatów</button>
                                                </div>
                                            </div>
                                        </div>																										
                                </div>
    
                                <div class="InvisibleInfoCourses" style="border-left: 5px solid <?php echo $color; ?>">
                                    <?php if (have_rows('terminy_warsztatow')) : $i = 0; ?>
                                        <div class="TerminySzkolen" style="padding: 0;">
                                            <?php while (have_rows('terminy_warsztatow')) : the_row();
                                                $i++;
                                                $hotele = get_sub_field('polecane_hotele');
                                                $zapisy = get_sub_field('stan_zapisow'); ?>
                                                <div class="InvisibleInfoCoursesDetails" <?php if ($zapisy == 'Sprzedane') : echo " style='opacity:.6;'";endif; ?>>
                                                    <div class="row">
                                                        <div class="col-sm-10">
                                                            <span><img src="<?php the_sub_field('logotyp') ?>" alt="<?php the_sub_field('lokalizacja') ?>"></span>
                                                            <span><i style="opacity: .6;" class="glyphicon glyphicon-time"></i><?php the_sub_field('data') ?></span>
                                                            <span><i style="opacity: .6;" class="glyphicon glyphicon-map-marker"></i><?php the_sub_field('lokalizacja') ?></span>
                                                            <span><i style="opacity: .6;" class="glyphicon glyphicon glyphicon-list-alt"></i><?php echo $zapisy; ?></span>
                                                        </div>
                                                        <div class="col-sm-2">
                                                            <div class="buttonsHereRight">
                                                                <!-- <a class="btn-lean btn-lean-sm" target="_blank" download="Formularz zgłoszeniowy" href="<?php the_sub_field('przycisk') ?>" onclick="gtag('event', 'szkolenia', {'event_category' : 'szkolenie-otwarte-lista-szkoleń','event_label' : '<?php the_title() ?> '});" <?php if ($zapisy == 'Sprzedane') : echo " style='display:none'";endif; ?>>Zapisz się</a> -->
                                                                <!-- <a class="btn-lean btn-lean-sm" href="<?php the_permalink(); ?>" onclick="gtag('event', 'szkolenia', {'event_category' : 'szkolenie-otwarte-lista-szkoleń','event_label' : '<?php the_title() ?> '});" <?php if ($zapisy == 'Sprzedane') : echo " style='display:none'"; endif; ?>>Zapisz się</a> -->
                                                                <a class="btn-lean btn-lean-sm" href="<?php the_permalink(); ?>" <?php if ($zapisy == 'Sprzedane') : echo " style='display:none'"; endif; ?>>Zapisz się</a>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            <?php endwhile; ?>
                                        </div>
                                    <?php endif ?>
                                </div>
                            </div>
                        </div>
                    </div>
                        
                    <?php endwhile; ?>
    
                    
    
                <?php wp_reset_postdata(); // so nothin' weird happens to other loops
                endif;
            }
        }
        
    ?>
  • Solving

    Expire Repeater Rows Based on Date Entered

    I have an events field for my homepage. There is a WYSIWYG field called calendar_item and a Date Picker field called time_expiry.

    I would like to compare today’s date against time_expiry and if time_expiry is greater, show calendar_item.

    This code seems like it should work, but I’m not getting any results when I view the page. Any idea what I’m missing?

    <?php date_default_timezone_set('America/New_York'); // set default timezone
        $today = date('Ymd');  // get today's date
        $expire = the_sub_field('time_expiry', 'option'); //get ACF expiration date
        $event = the_sub_field('calendar_item', 'option');  // This is our announcement field 
                    
        if ( have_rows( 'calendar' ) ) : while ( have_rows( 'calendar' ) ) : the_row();
            if( $expire > $today ) : //Is time_expiry greater than todays date?>
                <?php echo $event; // echo the event?>
            <?php endif; endwhile; else : endif;?>
  • Solved

    Trying to get values from nested repeater in admin area

    Hello,
    I have a nested repeater field and I’m trying to get some values from the nested repeater field on button click via AJAX.

    NOTE: I’ve tried yesterday to create this ticket but some error occurred. If there is a copy of this topic please delete it. This is the original

    Inside my repeater field “day_repeater” I have a date field “date” and a repeater field “accommodation” and inside the “accommodation” repeater field I have a text field “notes” and a post object field for my custom post type “accommodations”.

    I’ve created an AJAX script that runs the PHP function “email_sender” to get the values printed in the console.log (later I’m going to use the values to send them via email to my customers – there is a commented code for that).

    The problem is that I can’t get the values from my repeater fields (field “date” in repeater field “day_repeater” and field “notes” in nested repeater field “accommodation”) instead it returns null in the console log. I’ve tried the same code on the front end and I get all the values when I echo them.

    Here is my PHP code email-sender.php

    
    // Get values from repeater fields and send email to partner with Accommodation info
    add_action('wp_ajax_email_sender', 'email_sender');
    function email_sender($field) {
        if( have_rows('day_repeater') ):
            // loop through the rows of data
            while ( have_rows('day_repeater') ) : the_row();
    
            $date = get_sub_field('date'); // I need values from this field
            
                // LOOP FOR NESTED REPEATER FIELD
                if ( get_field('accommondation') ):
                    while( has_sub_field('accommondation') ) : the_row();
                    
                    $notes = the_sub_field('notes'); // I need values from this field
    
                    endwhile;
                endif;
            endwhile;
        endif;
    
        $post_id = $_POST["post_id"];
        $args = array(
            'p' => $post_id,
            'numberposts'=> -1,           // Fetch all posts...
            'post_type'=> 'accommodations',      // from the 'accommodation' CPT...
        );
    
        $accommodations = new WP_Query( $args );
    
        if ( $accommodations->have_posts() ) : while ( $accommodations->have_posts() ) : $accommodations->the_post();
            // Get values from CPT Accommodations
            $title = get_field('title');
            $partnerName = get_field('partner_name');
            $partnerEmail = get_field('partner_email');
            wp_reset_postdata();
            endwhile;
        endif;
    
        // Values that get printed in the console log
        $values = array(
            'title' => $title,
            'partnerName' => $partnerName,
            'notes' => $notes,
            'date' => $date
        );
        wp_send_json($values);
    
        /* // Send email to partner
            $subject = 'Test mail';
    
            ob_start(); ?>
    
            <?php echo ($title); ?>
    
            <?php echo ($partnerName); ?>
    
            <?php echo ($notes); ?>
    
            <?php
            $message = ob_get_contents();
            ob_end_clean();
            wp_mail( $partnerEmail, $subject, $message );
        */
        ?>
    <?php }
    //end
    
    //Add button to trigger AJAX script
    function my_acf_email_button($field) {
      echo '<div class="acf-field"><button type="submit" id="email_send" class="button">Send email</button></div>';
    	return $field;
    }
    add_filter('acf/prepare_field/name=send_inquery', 'my_acf_email_button');
    //end
    
    // Localize email-sender.js script to wordpress admin-ajax.php
    function js_email_send() {
      wp_enqueue_script ("ajax-email-sender", get_stylesheet_directory_uri() . "/inc/assets/js/email-sender.js", array('jquery')); 
      //ajax_email_sender will use to print admin-ajaxurl in email-sender.js
      wp_localize_script('ajax-email-sender', 'ajax_email_sender', array('ajaxurl' =>admin_url('admin-ajax.php')));
    } 
    add_action("admin_enqueue_scripts", "js_email_send");
    //end
    

    and here is my AJAX script email-sender.js

    
    jQuery(document).on( 'click', '#email_send', function( slanje ){
        slanje.preventDefault();
        // Picks post ID from relationship field
        var post_id = jQuery('.acf-row .acf-fields .acf-field .acf-input select option:selected').val();
    
        jQuery.ajax({
            url: ajax_email_sender.ajaxurl,
            type: "POST",
            dataType: 'json',
            data: {
                action: 'email_sender', // PHP function that is run
                post_id: post_id,
            },
            success: function(data){
                console.log(data)
            },
            error: function(error){
                console.log(error)
            },
        });
    });
    

    Also here is a screenshot of the console log and the repeater field
    Console log
    Console log

    Repeater field
    Repeater field

    Any idea how to get the values from the “date” and “note” fields in the console?
    I’m out of ideas and I don’t know what to try and where to look anymore. :/

    Thank you in advance!
    Kristijan

  • Solved

    Getting values from nested repeater in admin area

    Hello,
    I have a nested repeater field and I’m trying to get some values from the nested repeater field on button click via AJAX.

    Inside my repeater field “day_repeater” I have a date field “date” and a repeater field “accommodation” and inside the “accommodation” repeater field I have a text field “notes” and a post object field for my custom post type “accommodations”.

    I’ve created an AJAX script that runs the PHP function “email_sender” to get the values printed in the console.log (later I’m going to use the values to send them via email to my customers – there is a commented code for that).

    The problem is that I can’t get the values from my repeater fields (field “date” in repeater field “day_repeater” and field “notes” in nested repeater field “accommodation”) instead it returns null in the console log. I’ve tried the same code on the front end and I get all the values when I echo them.

    Here is my PHP code email-sender.php

    
    // Get values from repeater fields and send email to partner with Accommodation info
    add_action('wp_ajax_email_sender', 'email_sender');
    function email_sender($field) {
        if( have_rows('day_repeater') ):
            // loop through the rows of data
            while ( have_rows('day_repeater') ) : the_row();
    
            $date = get_sub_field('date'); // I need values from this field
            
                // LOOP FOR NESTED REPEATER FIELD
                if ( get_field('accommondation') ):
                    while( has_sub_field('accommondation') ) : the_row();
                    
                    $notes = the_sub_field('notes'); // I need values from this field
    
                    endwhile;
                endif;
            endwhile;
        endif;
    
        $post_id = $_POST["post_id"];
        $args = array(
            'p' => $post_id,
            'numberposts'=> -1,           // Fetch all posts...
            'post_type'=> 'accommodations',      // from the 'accommodation' CPT...
        );
    
        $accommodations = new WP_Query( $args );
    
        if ( $accommodations->have_posts() ) : while ( $accommodations->have_posts() ) : $accommodations->the_post();
            // Get values from CPT Accommodations
            $title = get_field('title');
            $partnerName = get_field('partner_name');
            $partnerEmail = get_field('partner_email');
            wp_reset_postdata();
            endwhile;
        endif;
    
        // Values that get printed in the console log
        $values = array(
            'title' => $title,
            'partnerName' => $partnerName,
            'notes' => $notes,
            'date' => $date
        );
        wp_send_json($values);
    
        /* // Send email to partner
            $subject = 'Test mail';
    
            ob_start(); ?>
    
            <p><?php echo ($title); ?></p>
            <p><?php echo ($partnerName); ?></p>
            <p><?php echo ($notes); ?></p>
    
            <?php
            $message = ob_get_contents();
            ob_end_clean();
            wp_mail( $partnerEmail, $subject, $message );
        */
        ?>
    <?php }
    //end
    
    //Add button to trigger AJAX script
    function my_acf_email_button($field) {
      echo '<div class="acf-field"><button type="submit" id="email_send" class="button">Send email</button></div>';
    	return $field;
    }
    add_filter('acf/prepare_field/name=send_inquery', 'my_acf_email_button');
    //end
    
    // Localize email-sender.js script to wordpress admin-ajax.php
    function js_email_send() {
      wp_enqueue_script ("ajax-email-sender", get_stylesheet_directory_uri() . "/inc/assets/js/email-sender.js", array('jquery')); 
      //ajax_email_sender will use to print admin-ajaxurl in email-sender.js
      wp_localize_script('ajax-email-sender', 'ajax_email_sender', array('ajaxurl' =>admin_url('admin-ajax.php')));
    } 
    add_action("admin_enqueue_scripts", "js_email_send");
    //end
    

    and here is my AJAX script email-sender.js

    
    jQuery(document).on( 'click', '#email_send', function( slanje ){
        slanje.preventDefault();
        // Picks post ID from relationship field
        var post_id = jQuery('.acf-row .acf-fields .acf-field .acf-input select option:selected').val();
    
        jQuery.ajax({
            url: ajax_email_sender.ajaxurl,
            type: "POST",
            dataType: 'json',
            data: {
                action: 'email_sender', // PHP function that is run
                post_id: post_id,
            },
            success: function(data){
                console.log(data)
            },
            error: function(error){
                console.log(error)
            },
        });
    });
    

    Also here is a screenshot of the console log and the repeater field
    Console log
    Console log

    Repeater field
    Repeater field

    Any idea how to get the values from the “date” and “note” fields in the console?
    I’m out of ideas and I don’t know what to try and where to look anymore. :/

    Thank you in advance!
    Kristijan

  • Solved

    Save ACF repeater group injected into existing WP Job Manager submit job form

    I’m injecting and ACF Pro field group into an existing WP Job Manager job submission form:

    
    /**
     * Inject ACF fields into route submission form.
     * This example uses the WP Job Manager Field Editor hook 
     * field to fire job_manager_field_actionhook_prefix_acf_repeater
     * 
     * @param array $field settings for field
     * @param string $key field key 
     */
    add_action( 'job_manager_field_actionhook_prefix_acf_repeater', 'prefix_acf_repeater', 10, 2 );
    function prefix_acf_repeater( $field, $key ) {
    	// We only want to add this on the front end. 
    	// The back end does not need custom display and saving.
    	if ( is_admin() ) {
    		return;
    	}
    
    	 // Insert ACF group field
    	 acf_form( [
    		 'new_post' => true,
    		 'post_id' => 'new_post', // Prevent old form values from being persistent
    		 'fields'=> [ 'field_5c9bf22960ed8'],
    		'return' => '', // No return value for WPJM compat. // https://support.advancedcustomfields.com/forums/users/jamesryder/replies/
    		'form' => false,
    		'honeypot' => false,
    	] );
    }
    

    I am not calling acf_form_head() because it conflicts with the WP Job Manager submission process. I am however, enqueueing acf_enqueue_scripts() so that the JS and CSS are loaded.

    
    add_action( 'init', 'prefix_acf_enqueue_scripts_manually', 1 );
    function prefix_acf_enqueue_scripts_manually() {
    	acf_enqueue_scripts();
    }
    

    I’ve created a callback function for save_post_job_listing (code at the end of this post) which allows me to look at $_POST and save my repeater fields, but this required building a complex custom save function which will break if the field structure is modified.

    Does ACF have a built in function that will allow me to manually trigger the saving of this group field? Or alternatively a more straight forward way of getting ACF and WPJM to work together?

    Here’s the custom save function:

    
    add_action( 'save_post_job_listing', 'prefix_save_group');
    function prefix_save_group( $post_id ) {
    	$fields = [];
    
    	$fields['days'] = [
    		'id'   => 'field_5c9bf22960ed8',
    		'name' => '_tsr_route_days'
    	];
    
    	$fields['stops'] = [
    		'id'   => 'field_5c9bf22962649',
    		'name' => 'stops'
    	];
    
    	$fields['stop_name'] = [
    		'id'   => 'field_5c9bf229635e9',
    		'name' => 'stop_name'
    	];
    
    	$fields['day_notes'] = [
    		'id'   => 'field_5c9bf25a6c3e0',
    		'name' => 'day_notes'
    	];	
    	
    	// Get array of days data from $_POST
    	$days_data = isset( $_POST['acf'][ $fields['days']['id'] ] )
    		? $_POST['acf'][ $fields['days']['id'] ]
    		: null;
    
    	// Bail if we have no data.	
    	if ( null === $days_data ) {
    		return;
    	}
    
    	// Day repeater (stores number of rows)
    	$days_data_count = count( $days_data );
    	$meta_key = $fields['days']['name'];
    	update_post_meta( $post_id, '_' . $meta_key, $fields['days']['id'] );
    	update_post_meta( $post_id, $meta_key,       $days_data_count );
    	
    	// Loop through days data and save it.
    	$day_counter = 0;
    	// Days
    	foreach ( $days_data as $day ) {
    		// Day
    		foreach ( $day as $day_field => $day_field_value ) {
    			// Day Stops
    			if ( $day_field === $fields['stops']['id'] ) {
    				// Number of stops
    				$stops = $day_field_value;
    				$stops_count = count( $stops );
    
    				$meta_key = $fields['days']['name'] . '_' .
    										$day_counter . '_' .
    										$fields['stops']['name'];
    
    				update_post_meta( $post_id, '_' . $meta_key, $day_field );
    				update_post_meta( $post_id, $meta_key,       $stops_count );
    				
    				$stop_counter = 0;
    				// Stop fields
    				foreach ( $stops as $stop ) {
    					// Stop field
    					foreach ( $stop as $stop_field => $stop_value ) {
    						// Stop Name
    						if ( $stop_field === $fields['stop_name']['id'] ) {
    
    							$meta_key = $fields['days']['name']  . '_' .
    													$day_counter . '_' .
    													$fields['stops']['name'] . '_' .
    													$stop_counter . '_' .
    													$fields['stop_name']['name'];
    
    							update_post_meta( $post_id, '_' . $meta_key, $stop_field );
    							update_post_meta( $post_id, $meta_key,       $stop_value );
    						}
    
    						// Stop Notes
    						if ( $stop_field === $fields['stop_notes']['id'] ) {
    
    							$meta_key = $fields['days']['name']  . '_' .
    													$day_counter . '_' .
    													$fields['stops']['name'] . '_' .
    													$stop_counter . '_' .
    													$fields['stop_notes']['name'];
    
    							update_post_meta( $post_id, '_' . $meta_key, $stop_field );
    							update_post_meta( $post_id, $meta_key,       $stop_value );
    						}
    					}
    					$stop_counter++;
    				} // Day stop
    			} // Day stops
    			
    			// Day Notes
    			if ( $day_field === $fields['day_notes']['id'] ) {
    
    				$meta_key = $fields['days']['name'] . '_' .
    										$day_counter . '_' .
    										$fields['day_notes']['name'];
    										
    				update_post_meta( $post_id, '_' . $meta_key, $day_field );
    				update_post_meta( $post_id, $meta_key,       $day_field_value );
    			}	// Day notes		
    		} // Day
    
    		$day_counter++;
    	} // Days
    }
    
  • Solved

    How to save repeater field injected into WPJM form

    I’m injecting and ACF Pro field group into an existing WP Job Manager job submission form:

    
    /**
     * Inject ACF fields into route submission form.
     * This example uses the WP Job Manager Field Editor hook 
     * field to fire job_manager_field_actionhook_prefix_acf_repeater
     * 
     * @param array $field settings for field
     * @param string $key field key 
     */
    add_action( 'job_manager_field_actionhook_prefix_acf_repeater', 'prefix_acf_repeater', 10, 2 );
    function prefix_acf_repeater( $field, $key ) {
    	// We only want to add this on the front end. 
    	// The back end does not need custom display and saving.
    	if ( is_admin() ) {
    		return;
    	}
    
    	 // Insert ACF group field
    	 acf_form( [
    		 'new_post' => true,
    		 'post_id' => 'new_post', // Prevent old form values from being persistent
    		 'fields'=> [ 'field_5c9bf22960ed8'],
    		'return' => '', // No return value for WPJM compat. // https://support.advancedcustomfields.com/forums/users/jamesryder/replies/
    		'form' => false,
    		'honeypot' => false,
    	] );
    }

    I am not calling acf_form_head() because it conflicts with the WP Job Manager submission process. I am however, enqueueing acf_enqueue_scripts() so that the JS and CSS are loaded.

    
    add_action( 'init', 'prefix_acf_enqueue_scripts_manually', 1 );
    function prefix_acf_enqueue_scripts_manually() {
    	acf_enqueue_scripts();
    }
    

    I’ve created a callback function for save_post_job_listing (code at the end of this post) which allows me to look at $_POST and save my repeater fields, but this required building a complex custom save function which will break if the field structure is modified.

    Does ACF have a built in function that will allow me to manually trigger the saving of this group field? Or alternatively a more straight forward way of getting ACF and WPJM to work together?

    It’s my understanding that the acf_update_{thing}() functions only work for fields that have already been saved and that these functions do not work with $_POST, but it also seems like there’s a better way of going about this than what I’m doing.

    Here’s the custom save function:

    
    add_action( 'save_post_job_listing', 'prefix_save_group');
    function prefix_save_group( $post_id ) {
    
    	$fields = tsr_acf_route_field_ids_days();
    	 $fields = [];
    
    	$fields['days'] = [
    		'id'   => 'field_5c9bf22960ed8',
    		'name' => '_tsr_route_days'
    	];
    
    	$fields['stops'] = [
    		'id'   => 'field_5c9bf22962649',
    		'name' => 'stops'
    	];
    
    	$fields['stop_name'] = [
    		'id'   => 'field_5c9bf229635e9',
    		'name' => 'stop_name'
    	];
    
    	$fields['day_notes'] = [
    		'id'   => 'field_5c9bf25a6c3e0',
    		'name' => 'day_notes'
    	];	
    	
    	// Get array of days data from $_POST
    	$days_data = isset( $_POST['acf'][ $fields['days']['id'] ] )
    		? $_POST['acf'][ $fields['days']['id'] ]
    		: null;
    
    	// Bail if we have no data.	
    	if ( null === $days_data ) {
    		return;
    	}
    
    	// Day repeater (stores number of rows)
    	$days_data_count = count( $days_data );
    	$meta_key = $fields['days']['name'];
    	update_post_meta( $post_id, '_' . $meta_key, $fields['days']['id'] );
    	update_post_meta( $post_id, $meta_key,       $days_data_count );
    	
    	// Loop through days data and save it.
    	$day_counter = 0;
    	// Days
    	foreach ( $days_data as $day ) {
    		// Day
    		foreach ( $day as $day_field => $day_field_value ) {
    			// Day Stops
    			if ( $day_field === $fields['stops']['id'] ) {
    				// Number of stops
    				$stops = $day_field_value;
    				$stops_count = count( $stops );
    
    				$meta_key = $fields['days']['name'] . '_' .
    										$day_counter . '_' .
    										$fields['stops']['name'];
    
    				update_post_meta( $post_id, '_' . $meta_key, $day_field );
    				update_post_meta( $post_id, $meta_key,       $stops_count );
    				
    				$stop_counter = 0;
    				// Stop fields
    				foreach ( $stops as $stop ) {
    					// Stop field
    					foreach ( $stop as $stop_field => $stop_value ) {
    						// Stop Name
    						if ( $stop_field === $fields['stop_name']['id'] ) {
    
    							$meta_key = $fields['days']['name']  . '_' .
    													$day_counter . '_' .
    													$fields['stops']['name'] . '_' .
    													$stop_counter . '_' .
    													$fields['stop_name']['name'];
    
    							update_post_meta( $post_id, '_' . $meta_key, $stop_field );
    							update_post_meta( $post_id, $meta_key,       $stop_value );
    						}
    
    						// Stop Notes
    						if ( $stop_field === $fields['stop_notes']['id'] ) {
    
    							$meta_key = $fields['days']['name']  . '_' .
    													$day_counter . '_' .
    													$fields['stops']['name'] . '_' .
    													$stop_counter . '_' .
    													$fields['stop_notes']['name'];
    
    							update_post_meta( $post_id, '_' . $meta_key, $stop_field );
    							update_post_meta( $post_id, $meta_key,       $stop_value );
    						}
    					}
    					$stop_counter++;
    				} // Day stop
    			} // Day stops
    			
    			// Day Notes
    			if ( $day_field === $fields['day_notes']['id'] ) {
    
    				$meta_key = $fields['days']['name'] . '_' .
    										$day_counter . '_' .
    										$fields['day_notes']['name'];
    										
    				update_post_meta( $post_id, '_' . $meta_key, $day_field );
    				update_post_meta( $post_id, $meta_key,       $day_field_value );
    			}	// Day notes		
    		} // Day
    
    		$day_counter++;
    	} // Days
    }
    
    
Viewing 25 results - 26 through 50 (of 270 total)