Support

Account

Home Forums Search Search Results for 'event date repeater'

Search Results for 'event date repeater'

reply

  • Hi @maira

    If you need to order the events based on the date in a repeater, then you need to query the repeater instead of the events. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/querying-the-database-for-repeater-sub-field-values/.

    You also need to select the field values based on the current time and remove the duplicated post ID. This page should give you more idea about it: http://stackoverflow.com/questions/4682621/sql-how-to-select-rows-from-a-table-while-ignoring-the-duplicate-field-values.

    If you need more help to create the SQL query, please visit WordPress and MySQL community.

    I hope this helps 🙂

  • sorry, that’s a typo on my part, it should be have_rows()

    
    if (have_rows('repeater_field_name')) {
      $dates = array();
      while(have_rows('repeater_field_name')) {
        the_row();
        $date = get_sub_field('date_subfield_name');
        if ($date) {
          $dates[] = date_i18n('j \d\e\ F \-\ G \h\s', strtotime($date_3));
        }
      } // end while have rows
      if ( $dates) {
        echo '<h5>UPCOMING EVENTS</h5><p> ' . implode(' | ', $dates) . '</p>';
      }
    } // end if have rows
    
  • To do this with a repeater field it would look something like this, and I will include information from your other topic.

    
    if (have_row('repeater_field_name')) {
      $dates = array();
      while(have_row('repeater_field_name')) {
        the_row();
        $date = get_sub_field('date_subfield_name');
        if ($date) {
          $dates[] = date_i18n('j \d\e\ F \-\ G \h\s', strtotime($date_3));
        }
      } // end while have rows
      if ( $dates) {
        echo '<h5>UPCOMING EVENTS</h5><p> ' . implode(' | ', $dates) . '</p>';
      }
    } // end if have rows
    
  • James, appreciate your help. I have already spent sometime looking through forums trying to find a solution for what I need to no avail.

    I pretty much need my loop to output a list of events based on a repeater subfield where the backend user can assign to the event one or several dates, and the loop needs to sort upcoming events sorted in order by the earliest date and keep them active until the latest date set in the repeater.

  • Hi @vefusion

    There are a lot of threads that are talking about event date field in a repeater. Here are some of those threads:

    https://support.advancedcustomfields.com/forums/topic/sort-by-date-a-repeater-field/

    https://support.advancedcustomfields.com/forums/topic/event-list-ordered-by-repeater-date/

    https://support.advancedcustomfields.com/forums/topic/calendar-by-month-with-date-repeater/

    You can also search them here:

    https://support.advancedcustomfields.com/forums/search?bbp_search=event+date+repeater

    Could you please check those threads first? If you have any difficulties later, just let me know 🙂

  • Hi @mpayumo

    It seems you’re using the old syntax for the repeater. Could you please try the new syntax and debug the variables like this:

    while ( have_rows('dates') ) : the_row();
     
        if(get_sub_field('event_date')){
            $post_id = get_the_ID(); // Set the current post ID
            $event_date = get_sub_field('event_date'); 
            $event_location = get_field('event_venue');
            $permalink = get_permalink();
            $thumbnail = get_the_post_thumbnail($post_id);
            $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id($post_id), 'thumbnail');
            $ticket = get_sub_field('event_ticket_link');
            $price = get_field('event_price');
            $title = get_the_title();
            $terms = get_the_terms($post_id, 'genre');
            $url = wp_get_attachment_image_src($id,'event-thumb', true);
    
            if($event_date >= $today){
                if(isset($events[$post_id])){
                    $events[$post_id]['dates'][] = $event_date;
                    if($event_date < $events[$post_id]['earliest_date']){
                        $events[$post_id]['earliest_date'] = $event_date;
                    }
                }
                else{
                    $events[$post_id] = array(
                        'title' => $title,
                        'permalink' => $permalink,
                        'thumb' => $thumbnail,
                        'thumbnail_src' => $thumbnail_src,
                        'price' => $price,
                        'ticket' => $ticket,
                        'dates' => array($event_date),
                        'earliest_date' => $event_date,
                        'terms' => $terms
                    );
    
                }
    
            }
            
            $i++;
        }
        
        echo "<pre>";
        
        echo "======== Start debugging the events variable ========";
        print_r($events[$post_id]);
        echo "======== End debugging the events variable ========";
        
        echo "======== Start debugging the events date ========";
        print_r(get_sub_field('event_date'));
        echo "======== End debugging the events date ========";
        
        echo "</pre>";
    
    endwhile;

    Thanks 🙂

  • Hi @mpayumo

    Yes, it seems that the content is returned correctly. Next, could you please debug all key variables like $events.

    Also, could you please check if the repeater returns correct data like this:

    echo "<pre>";
    while ( $lulus->have_posts() ) : $lulus->the_post();
    
        $dates = get_field('dates');
        print_r($dates);
    
    endwhile;
    echo "</pre>";

    If that doesn’t work, could you please try to set the post ID manually like this:

    $dates = get_field('dates', 99);

    Where ’99’ is the post ID.

    Thanks 🙂

  • Hello James

    Thank you very mutch for your help. I decided to change method.

    I have created one page “calendar” with my repeater and i use relationship for the relation with my event.

    my current code is :

    <?php
    /**
     * Template Name: Test Calendrier
     */
    ?>
    
    <?php get_header(); ?>
    <div class="title-page no-thumb">
        <?php
        if( have_rows('calendrier') ) :
            while ( have_rows('calendrier') ) : 
                the_row();
                $date_debut = get_sub_field('jour_debut');
                $mois_spectacle = explode(" ", $date_debut)[1];
                
                echo '<h1>'.$mois_spectacle.'</h1>';
        ?>  
            <?php 
            $posts = get_sub_field('spectacle');
            ?>
                <?php
                foreach( $posts as $post):
                ?>
                    <?php setup_postdata($post); ?>
                    <div>
                        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                        <span>Date début : <?php echo $date_debut ?></span>
                    </div>
                <?php
                endforeach;
                ?>
            <?php wp_reset_postdata();?>
    
        <?php 
        endwhile;endif;
        ?>
    </div>
    <?php
    get_footer(); ?>

    now i must merge the month and event similar.

    but I do not know how…

  • Hi @trainsrenton

    You need to use the $rows variable that holds the wpdb result. Something like this:

    $rows = $wpdb->get_results($wpdb->prepare( 
                "
                SELECT * 
                FROM {$wpdb->prefix}postmeta
                WHERE meta_key LIKE %s
                ",
                'calendrier_%_jour_debut'
            ));
    
    // vars
    $order = array();
    
    // populate order
    foreach( $rows as $i => $row ) {
    	
    	$order[ $i ] = $row['meta_value'];
    	
    }
    
    // multisort
    array_multisort( $order, SORT_ASC, $rows );
    
    // Temporary month variable
    $current_month = null;
    
    // Loop through the returned rows
    foreach( $rows as $row){
        
        // Convert the date string to PHP datetime
        $date = DateTime::createFromFormat('Ymd', $row['meta_value']);
        
        // Get the month
        $month = $date->format('F');
        
        // Echo the months only once
        if( $current_month != $month ){
            echo $month . "\r\n";
            $current_month = $month;
        }
        
        // Show the date string
        echo $row['meta_value'] . "\r\n";
        
        // Get the related post
        $thepost = get_post($row['post_id']);
        
        // Show it if you want
        print_r($thepost);
        
        // Get the event repeater for the related post
        $calendrier = get_field('calendrier', $thepost->ID);
        
        // Show it if you want
        print_r($calendrier);
    }

    Hope this helps 🙂

  • Hi @imaginedd

    Thank you for showing the way 🙂

    I have tried that example code and now i have all events from each band on specific date. The problem is that i’m not sure how to sort it by time sub field.

    Here is the code:

    <?php
    $date = "20160620";
    // args
    $args = array(
    	'numberposts'	=> -1,
    	'post_type'		=> 'band',
    	'meta_query'	=> array(
    		'relation'		=> 'OR',
    		array(
    			'key'		=> 'events_%_date',
    			'compare'	=> '==',
    			'value'		=> $date,
    		)
    	)
    );
    
    $the_query = new WP_Query( $args );
    ?>
    
    <?php if( $the_query->have_posts() ): ?>
    	<div class="events">
    	<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    		<?php
    		if(have_rows('events')):
    		   while(have_rows('events')): the_row();
    			  if(get_sub_field('date') == $date):
    				 the_sub_field('time');
    				 echo ' - ';
    				 the_title();
    				 echo '<br>';
    			  endif;
    		   endwhile;
    		endif;
    		?>
    	<?php endwhile; ?>
    	</div>
    <?php endif; ?>
    
    <?php wp_reset_query();	 ?>

    By this code i’m getting such events lst:

    1500 – Band1 (1st show)
    1800 – Band 1 (2nd show)
    1400 – Band 2 (2nd show)
    1200 – Band 2 (1st show)

    I’m not sure how to use krsort() with repeater. Can you help me with this?

    Many thanks!

  • Hi @geert

    Hard to know where to start…

    Okay, so most people on the web with a WordPress site probably has shared hosting (I’m guessing). They have little to no control over the servers settings and limitations. Here’s some standard PHP values which are unlikely to be set higher in such shared hosting:
    http://php.net/manual/en/info.configuration.php

    disclaimer: I’m not gonna research everything here before (limited time) so some is a little bit of guesswork when it comes to numbers.

    max_input_vars there is one of the most interesting ones. Basically it says that PHP will accept a maximum of 1000 input fields to send to a single request (page load). In the case of WP admin that would likely be a POST request. WordPress per default already have quite a bit of fields for a standard edit screen. There’s a whole bunch of hidden fields as well as formats, categories, tags, featured image, title, editor, permalink, visibility, status etc. Let’s say you also have a few regular custom fields. Then you also add a repeater field to this. Each row might contain 2-10 fields + some hidden fields ACF uses to keep track of everything. Maybe you even have nested repeaters! So for each row there’s 2-10 fields + a nested repeater which in term contains 2-10 fields. And say you add in a gallery field there as well. That’s at the very least 1 field for each image.

    You’re quickly gonna find that you hit the 1000 input vars limit if you abuse repeaters. That’s gonna stop you from adding any new content to the page before you delete other. That in itself should be enough to reconsider huge repeater fields. But to make matters worse there’s also server limits like max_execution_time and max_allowed_packet (mysql). Saving all these fields will take some time and if you’re not on a great internet connection you may hit the max_excecution_time which will lead to your page save ending abruptly and unfinished. max_allowed_packet is a variable for mySQL which basically limits how large of data chunk you may insert in one go. It’s much harder to hit but it’s possible.

    If you’d be on a VPS you could prevent all of this by just upping your server stats. However you’ll still get a very slow admin experience and let’s face it, you’re patching a leaking boat and probably have to pay a hefty price for it (big servers aren’t cheap).

    Then there’s also the issue of WordPress database structure and the performance of WP_Query. 10up has written a great article on performance with WP_Query and one of the things to avoid is post meta lookup. Usually there’s no choice BUT we can at least do what we can to use simple post meta like a single date field or a boolean. And of course try to minimize the amount of post meta for each single post. https://10up.github.io/Engineering-Best-Practices/php/#performance
    Consider that ACF adds two rows to wp_postmeta for each field (both regular and sub fields).

    So if we can refactor our data structure to use a custom post type which would contain some fields and then perhaps link different posts/post types together with the post object or relationship field we’ll end up with safer and quicker admin requests, faster and often more versatile use of wp_queries in our front end and a better DB structure more fitting of WordPress strengths and weaknesses.

    It’s hard to say a number of repeater rows that’d be “too much” since it depends on what they contain. But for me, if I find that I’d end up with more than 20-30 row of simpler repeater data or 10-15 rows of more complex ones I would consider a different solution. Sometimes it’s hard to predict tho. We’ve had customers where they were supposed to use repeaters for just a few categories of Press media attachments but they ended up dumping soooo much media there that we eventually had to rebuild it for them with a CPT where each post was a single media file and a taxonomy for the categories of media.

    Hope that was a sufficient answer 🙂

  • Hi Jonathan,

    That’s a very thoughtful response and I appreciate it. But I think we got off track with your first assumption. All the information is specific to a company. So each CPT “reports” post is built around a single company.

    Let’s see if I can give you a visual…

    We have a custom post type called “reports” and we write a single report for each company.

    CPT “Reports”:
    –Company A
    –Company B
    –Company C

    So in the example above we have three “posts” in our custom post type.

    Each post makes use of several dozen custom fields, including text, selects, taxonomies and repeaters, etc.

    CPT “Reports”
    –Company A
    — title
    — description
    — taxonomy
    — repeater for “events”
    — event 1
    — event 2
    — etc.
    — commentary
    — price
    — etc
    –Company B… same fields as company A
    –Company C… same again…

    Now, the report is published and a customer can view the report for Company A. This is the key–> when things need to be updated, the analyst uses a front end form to go into that Company A “reports” CPT and he updates the post. (In other words, he does NOT create a new report for that company.)

    (It is important that the analyst works on a single view of the company on one page/form — it would be difficult to enter information about a company by jumping around to different forms.)

    Some fields in the report never change — like “title.” Some fields are overwritten, like “price.” Other fields are added to over time, like the repeater field on “events.” We do this because we keep track of historical events that were logged over time and we display them in a data table.

    The setup is working great for us except for the fact that those repeater fields will get very long over time.

    Does that make more sense?

  • Hi Jonathan,

    Sorry — I might not be explaining things correctly. As you say, we are already set up so each report is a custom post type and each single report is made up of a bunch of fields. So let me give you a more specific example:

    One field in our front-end form uses a repeater to enter ‘events’ that occur on a ‘date.’ Say, an ‘Earnings announcement’ happened on ‘April 14th.’ Reports are edited weekly by returning to the front-end form to make edits.

    After a while — say one year — there may now be 50+ entries in that one repeater field (and there are more repeaters in the form). Soon there may be 100 or 200 entries. So when the analyst goes to the form to enter another ‘event’ — they have to scroll through all the previous entries to get to the bottom to enter a new event.

    This is where creating pagination, in a repeater field, in a front-end form, would help compact things. Does that make more sense? Screenshot attached.

    Dan

  • HI @foxnove,

    Thanks for the post.

    For the relationship nested in the Repeater, you will need to change the_sub_field() function into a get_sub_field() function and then create a loop to fetch the post objects. Your code should then look like so:

    <?php if( have_rows('event') ): ?>
    
    	<div class="locations">
    
    	<?php while( have_rows('event') ): the_row(); ?>
    
    		<div class="location" style="border-bottom:1px solid #fff;">
    
                
               <?php $posts = get_sub_field('location'); ?> 
                           <?php if( $posts ): ?>
                              <ul>
                              <?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
                              <?php setup_postdata($post); ?>
                              <li>
                              <a href="<?php the_permalink(); ?>"><?php the_title(); ?>                                </a>
                              <span>Custom field from $post: <?php the_field('author'); ?></span>
                              </li>
                              <?php endforeach; ?>
                               </ul>
                              <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
                              <?php endif; ?>
    
    			<?php if( have_rows('date_event') ): ?>
    
    				<ul class="staff-members">
    
    					<?php while( have_rows('date_event') ): the_row(); ?>
    						<li><?php the_sub_field('date'); //repeater field  OK ?></li>
    
    					<?php endwhile; ?>
    
    				</ul>
    
    			<?php endif; ?>
    		</div>
    
    	<?php endwhile; ?>
    	</div>
    
    <?php endif; ?>
  • Using the acf validation filters it is possible to prevent the user from selecting the same choice more than once.

    Let’s say that you have a repeater field with a key of ‘field_0123456789abc’ and it has a sub field with a key of ‘field_cba9876543210’ and you want to make sure that the sub field in each rows has a unique value.

    
    <?php 
    // validate one row of a repeater against other rows of same repeater
    add_filter('acf/validate_value/key=field_cba9876543210', 'sub_field_unique', 10, 3);
    function sub_field_unique($valid, $value, $field, $input) {
      if (!$valid) {
        return $valid;
      }
      $repeater = 'field_0123456789abc';
      $subfield = 'field_cba9876543210';
      $values = $_POST['acf'][$repeater];
      if (!count($values)) {
        return $valid;
      }
      // extract the current row index from $input
      $current_row = preg_replace('/^\s*acf\[[^\]]+\]\[([^\]]+)\].*$/', '\1', $input);
      $count = count($values);
      foreach ($values as $index => $row) {
        if ($index != $current_row && $value == $row[$subfield]) {
          $valid = 'value must be unique';
        }
      }
      return $valid;
    }
    ?>
    

    The exact logic may be different depending on the field type.

  • Hi @snixx

    It’s because ACF will show the repeater field based on your field group setting, but it still has no initial value in the database. It will prevent the add_row() function to add the row because it can’t find it.

    Have you tried the update_field() function instead?

    Thanks!

  • Hi James
    Thak you!

    This is my JSON-File.
    “field_56c19dd4c3e9c” is the repeater I want the alphabetical list of.

    
    {
        "key": "group_56cd64f9096fa",
        "title": "Veranstaltungen",
        "fields": [
            {
                "key": "field_54c7409720a78",
                "label": "Date",
                "name": "date",
                "type": "date_picker",
                "instructions": "",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "",
                    "id": ""
                },
                "display_format": "l, d. F Y",
                "return_format": "Ymd",
                "first_day": 1
            },
            {
                "key": "field_54c7412220a79",
                "label": "Time",
                "name": "time",
                "type": "text",
                "instructions": "",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "",
                    "id": ""
                },
                "default_value": "",
                "placeholder": "",
                "prepend": "",
                "append": "",
                "maxlength": "",
                "readonly": 0,
                "disabled": 0
            },
            {
                "key": "field_54c7a407e1264",
                "label": "Event-Type",
                "name": "type",
                "type": "text",
                "instructions": "",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "",
                    "id": ""
                },
                "default_value": "",
                "placeholder": "",
                "prepend": "",
                "append": "",
                "maxlength": "",
                "readonly": 0,
                "disabled": 0
            },
            {
                "key": "field_54c7a45be1265",
                "label": "Entry fee",
                "name": "entry",
                "type": "text",
                "instructions": "",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "",
                    "id": ""
                },
                "default_value": "",
                "placeholder": "",
                "prepend": "",
                "append": "",
                "maxlength": "",
                "readonly": 0,
                "disabled": 0
            },
            {
                "key": "field_54d9d07b10c0a",
                "label": "Supporting Act",
                "name": "support",
                "type": "text",
                "instructions": "Supporting-Act",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "",
                    "id": ""
                },
                "default_value": "",
                "placeholder": "",
                "prepend": "",
                "append": "",
                "maxlength": "",
                "readonly": 0,
                "disabled": 0
            },
            {
                "key": "field_54c8992084720",
                "label": "Links",
                "name": "links",
                "type": "repeater",
                "instructions": "",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "",
                    "id": ""
                },
                "row_min": "",
                "row_limit": "",
                "layout": "table",
                "button_label": "Add new link",
                "min": 0,
                "max": 0,
                "collapsed": "",
                "sub_fields": [
                    {
                        "key": "field_54c8992e84721",
                        "label": "Linkname",
                        "name": "linkname",
                        "type": "text",
                        "instructions": "",
                        "required": 0,
                        "conditional_logic": 0,
                        "wrapper": {
                            "width": "",
                            "class": "",
                            "id": ""
                        },
                        "default_value": "",
                        "placeholder": "",
                        "prepend": "",
                        "append": "",
                        "formatting": "html",
                        "maxlength": "",
                        "readonly": 0,
                        "disabled": 0
                    },
                    {
                        "key": "field_54c8993c84722",
                        "label": "Linkadresse",
                        "name": "linkadresse",
                        "type": "text",
                        "instructions": "",
                        "required": 0,
                        "conditional_logic": 0,
                        "wrapper": {
                            "width": "",
                            "class": "",
                            "id": ""
                        },
                        "default_value": "",
                        "placeholder": "",
                        "prepend": "",
                        "append": "",
                        "formatting": "html",
                        "maxlength": "",
                        "readonly": 0,
                        "disabled": 0
                    }
                ]
            },
            {
                "key": "field_56c19dd4c3e9c",
                "label": "Artists",
                "name": "artists",
                "type": "repeater",
                "instructions": "This field is used for the Artist-List.",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "",
                    "id": ""
                },
                "row_min": "",
                "row_limit": "",
                "layout": "table",
                "button_label": "Add Artist",
                "min": 0,
                "max": 0,
                "collapsed": "",
                "sub_fields": [
                    {
                        "key": "field_56c19de1c3e9d",
                        "label": "Artist Name",
                        "name": "artistname",
                        "type": "text",
                        "instructions": "",
                        "required": 0,
                        "conditional_logic": 0,
                        "wrapper": {
                            "width": "",
                            "class": "",
                            "id": ""
                        },
                        "default_value": "",
                        "placeholder": "",
                        "prepend": "",
                        "append": "",
                        "formatting": "html",
                        "maxlength": "",
                        "readonly": 0,
                        "disabled": 0
                    },
                    {
                        "key": "field_56c1abe6bf667",
                        "label": "Artist-Website",
                        "name": "artistweb",
                        "type": "text",
                        "instructions": "",
                        "required": 0,
                        "conditional_logic": 0,
                        "wrapper": {
                            "width": "",
                            "class": "",
                            "id": ""
                        },
                        "default_value": "",
                        "placeholder": "",
                        "prepend": "",
                        "append": "",
                        "formatting": "html",
                        "maxlength": "",
                        "readonly": 0,
                        "disabled": 0
                    }
                ]
            },
            {
                "key": "field_54e5d86e27b60",
                "label": "Presales",
                "name": "presales",
                "type": "text",
                "instructions": "Link zur Vorverkaufsseite \"http:\/\/www....\"",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "",
                    "id": ""
                },
                "default_value": "",
                "placeholder": "",
                "prepend": "",
                "append": "",
                "maxlength": "",
                "readonly": 0,
                "disabled": 0
            },
            {
                "key": "field_54c8b1bf11fde",
                "label": "Image Gallery",
                "name": "gallery",
                "type": "repeater",
                "instructions": "",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "",
                    "id": ""
                },
                "collapsed": "",
                "min": "",
                "max": "",
                "layout": "table",
                "button_label": "Fotos hinzuf\u00fcgen",
                "sub_fields": [
                    {
                        "key": "field_54c8b1dc11fdf",
                        "label": "Bild",
                        "name": "bild",
                        "type": "image",
                        "instructions": "",
                        "required": 0,
                        "conditional_logic": 0,
                        "wrapper": {
                            "width": "",
                            "class": "",
                            "id": ""
                        },
                        "preview_size": "thumbnail",
                        "library": "all",
                        "return_format": "id",
                        "min_width": 0,
                        "min_height": 0,
                        "min_size": 0,
                        "max_width": 0,
                        "max_height": 0,
                        "max_size": 0,
                        "mime_types": ""
                    }
                ]
            },
            {
                "key": "field_54cb98c819900",
                "label": "R\u00e9sum\u00e9",
                "name": "resume",
                "type": "wysiwyg",
                "instructions": "Das ist ein abschliessender Text zum Event. Dieser wird angezeigt sobald Fotos in der Fotogalerie sind.",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "",
                    "id": ""
                },
                "default_value": "",
                "tabs": "all",
                "toolbar": "full",
                "media_upload": 1
            }
        ],
        "location": [
            [
                {
                    "param": "post_type",
                    "operator": "==",
                    "value": "post"
                }
            ]
        ],
        "menu_order": 5,
        "position": "normal",
        "style": "seamless",
        "label_placement": "top",
        "instruction_placement": "label",
        "hide_on_screen": "",
        "active": 1,
        "description": "",
        "modified": 1456303465
    }
    
  • Can you pre-populate a repeater field, yes.

    You can use an acf/load_value filter. http://www.advancedcustomfields.com/resources/acfload_value/

    
    function my_acf_load_value($value, $post_id, $field) {
      if ($value !== NULL) {
        // if the value is exactly NULL it means
        // the field has never been updated
        // we don't want to change fields that have already been editied
        return $value;
      }
      // set the new field value
      $value = array(
        // add a nested array for each row
        array(
          // add an array item for each sub field
          'field_name_1' => 'Value for Field 1',
          'field_name_2' => 'Value for Field 2'
        )
      );
      return $value;
    }
    

    The second part of the question, can you prevent the rows of the repeater from being reordered or edited? As far as I know this can’t be done.

  • if you dont try to merge your posts into one list you could try this:

    <ul class="program-list">
    <?php query_posts('cat=2'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php
    $repeater = get_field('program_repeater');
    foreach( $repeater as $key => $row ) {
    		$thedate = $row['program_repeater_date']; 
    		$column_id[ $key ] = strtotime($thedate);
    	}
    array_multisort( $column_id, SORT_ASC, $repeater );
    	foreach( $repeater  as $row ){
    
    $dateDayNumber = date_i18n("d", strtotime(get_sub_field('program_repeater_date')));
    			$dateMonthNumber = date_i18n("m", strtotime(get_sub_field('program_repeater_date')));
    			$dateDayOrg = date_i18n("l", strtotime(get_sub_field('program_repeater_date')));
    			$dateDay = substr($dateDayOrg, 0, 2);
    			$dateTime = get_sub_field('program_repeater_time');
    			$specialEvent = get_sub_field('program_repeater_special');
    			$mainTitle = get_the_title();
    			$subTitle = get_field('sub_text');
    			$rowSeatsId = get_sub_field('program_repeater_rowseats_id');
    			?>
    			
    			<li>
    				<div class="specialEvent"><?php if( $specialEvent ): ?><?php echo $specialEvent; ?><?php else: ?>&nbsp;<?php endif; ?></div>
    				<div class="dateDayNumber"><?php echo $dateDayNumber; ?></div>
    				<div class="dateMonthNumber"><?php echo $dateMonthNumber; ?></div>
    				<div class="dateDay"><?php echo $dateDay; ?></div>
    				<div class="v-line-zick-zack"></div>
    				<div class="dateTime"><?php echo $dateTime; ?></div>
    				<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
    					<div class="mainTitle"><?php echo $mainTitle; ?></div>
    					<div class="subTitle"><?php echo $subTitle; ?></div>
    				</a>
    				<a href="<?php the_permalink(); ?><?php echo "?id=" . $rowSeatsId; ?>" title="<?php the_title_attribute(); ?>">
    					<div class="ticket-link">Tickets kaufen</div>
    				</a>
    				<div class="clear"></div>
    			</li>
    <?php } ?>
    <?php endwhile; endif; ?>
    <?php wp_reset_query(); ?>
    </ul>

    If you try to merge them => you need to build a array first, order it, and echo it after that.

    try to adapt a solution like this or this

  • Hi, I believe i’m doing both!

    I want to create an add-on for AFC to create a new field type, however when you assign that new field to a (eg. post), I need to show a repeater (per-defined) of a new field type and use it’s values to create a custom front-end output.

    – To give an example, I want to create a calendar plugin, that can be assigned to any post type.
    – It will have a repeater to add events (repeater of text(title), date&time(the new field type) )
    – Then in the output will show the calendar with its events

    At the moment I have done that by creating theme templates, CPT and exporting ACF code inside the theme, which is utilizes ACF as you said.

  • Like I said above, I have flagged this thread for E to look at when he has time but I can’t say if he will or if he will comment.

    I run into the same problem with ACF pro. It has some more optimization but eventually you still run into the problem.

    The site I mentioned above uses ACF Pro and to give you an idea of the problem I was facing.

    One post type has a repeater field that lets the client add sections to a page. Each section actually represents a page of a printed publication. Each section can have up to 7 content areas. Each content area has controls that allow the client to specify the formatting of the block including padding, background, border, font color and I’m sure some things I don’t remember. So ff they add 10 sections that means they have up to 70 WYSUWYG editors plus the related settings fields for each. I created an interface using ACF Pro that was extremely easy for them to use, but I did not realize I would run into the updating problem.

    Having run into this problem I now make a special effort to think about how much data the client might try to add. If I could go back to the beginning of that project I would create a parent/child structure to the custom post type where each “Page” section was a different post. It would have been a bit more difficult for the client to use but would have avoided the problem that they now have to work around.

    This hasn’t changed my opinion of ACF, I still think it’s the best tool for the job I need to do, but I have a better handle on it’s limitations.

    What I would like to see is not using the WP update meta function and use $wpdb to build queries to insert or update all of the needed database rows in a single query. I started looking into this when I had the problem but could not figure out a safe way of bypassing or cancelling what ACF was doing. I would still like to figure something out but it’s been put on a back burner do to my current workload and other projects that I need to get done.

  • i think you need to loop through your CP and Repeater and build a array first, and after that echo events out of that array.
    important for ordering by date is: that you set Return Format to Ymd (you can change this later with date/date_i18n)

    /*build and fill: cp-loop and repeater loop*/
    if(have_posts()) : while(have_posts()) : the_post(); 
    $get_event_name = get_field('my_event_name');
    if( have_rows('repeater_field_name') ):
        while ( have_rows('repeater_field_name') ) : the_row();
    
    $my_event_date = get_sub_field('my_event_date');
    $get_date = (get_sub_field('my_event_date'));
    $get_date_day = date('d', strtotime($get_date));
    $get_date_month = date('m', strtotime($get_date));
    $get_date_year = date('Y', strtotime($get_date));
    $the_ID = get_the_ID();
    
    /*of course you can extend this with additional fields or infos for that event that you can use later*/
    $array[$get_date_year][$get_date_month][$get_date_day][$the_ID]['date'] = $my_event_date;
    $array[$get_date_year][$get_date_month][$get_date_day][$the_ID]['name'] = $my_event_name;
    endwhile;
    endif;
    
    endwhile;
    endif;
    
    /*output*/
    /*i assume you extract year and month from today (example here next month)*/
    $today = date('Ymd');
    $d = new DateTime($today);
    $d->modify( 'first day of next month' );
    $year_youwish = $d->format( 'Y' );
    $month_youwish = $d->format( 'm' );
    
    $array_month_youwish = $array[$year_youwish][$month_youwish];
    asort($array_month_youwish);
    
    foreach ($array_month_youwish as $key_day => $row_day){
    foreach ($row_day as $key_event => $row_id){
    $event_name = $row_id['name'];
    $event_date = $row_id['date'];
    $event_date_pretty = date_i18n( 'j. F Y', $event_date);
    echo $event_date_pretty .' : '. $event_name;
    }
    }
    

    hope that help

  • Hi John,

    Thanks for reply and sorry for the delay.

    It’s not just one field. It’s a set of fields. I’ve modified the standard post. Please see the following page: http://dailycapital.com.au/canberra_events/venice-the-golden-age-presented-by-oriana-chorale/

    You will notice that almost all fields (start date, end date, address on map, cost, etc) except the event title itself is from ACF. (The event title is actually the post title).

    And no , it’s not a part of a repeater.

    Thank you very much in advance for your help.
    K

  • <?php if( have_rows('event') ): ?>
    
    	<div class="locations">
    
    	<?php while( have_rows('event') ): the_row(); ?>
    
    		<div class="location" style="border-bottom:1px solid #fff;">
    
                
               <?php the_sub_field('location'); //relationship field  ERRO ?> 
    
    			<?php if( have_rows('date_event') ): ?>
    
    				<ul class="staff-members">
    
    					<?php while( have_rows('date_event') ): the_row(); ?>
    						<li><?php the_sub_field('date'); //repeater field  OK ?></li>
    
    					<?php endwhile; ?>
    
    				</ul>
    
    			<?php endif; ?>
    		</div>
    
    	<?php endwhile; ?>
    	</div>
    
    <?php endif; ?>
  • I’ve been looking into this a bit since I commented in the other topic. I found an interesting topic on stackoverflow. They suggest using update_field() on the repeater, supplying an array of values instead of trying to add sub fields.

    http://stackoverflow.com/questions/24879399/wordpress-acf-how-to-add-rows-to-a-repeater-field-attached-to-a-user-via-custom

    With this in mind I took a look at the documentation for update_field() http://www.advancedcustomfields.com/resources/update_field/. This is actually covered there, it says taxonomy, but it could be used on a post, taxonomy is just used so that the example has a duel purpose.

    
    /*
    *  add a repeater row on a taxonomy!!!
    */
    
    $field_key = "repeater_field";
    $post_id = "event_123";
    $value = get_field($field_key, $post_id);
    $value[] = array("sub_field_1" => "Foo", "sub_field_2" => "Bar");
    update_field( $field_key, $value, $post_id );
    
Viewing 25 results - 226 through 250 (of 270 total)