Support

Account

Home Forums Search Search Results for 'event date repeater'

Search Results for 'event date repeater'

topic

  • Solving

    Using ACF Repeater to Access Event Calendar Serialized Meta

    Hi guys, I want a bit more control over some custom fields used in Events Calendar, it’s for their Ticket fieldset, but I am finding it hard to access the data because it is serialized repeater, I was thinking about accessing the fields using acf repeater (if that is possible) but I am concerned how I would add more rows and save the data to the correct format below, I saw another post regarding repeater fields and tried it but I think this is a little different and I couldnt get it working,any idea would be grateful thanks

    a:16:{i:0;a:5:{s:4:”type”;s:4:”text”;s:8:”required”;s:0:””;s:5:”label”;s:20:”Full Name of Guest 1″;s:4:”slug”;s:20:”full-name-of-guest-1″;s:5:”extra”;a:0:{}}i:1;a:5:{s:4:”type”;s:6:”select”;s:8:”required”;s:0:””;s:5:”label”;s:9:”T-Shirt 1″;s:4:”slug”;s:9:”t-shirt-1″;s:5:”extra”;a:1:{s:7:”options”;a:6:{i:0;s:5:”Small”;i:1;s:6:”Medium”;i:2;s:5:”Large”;i:3;s:2:”XL”;i:4;s:3:”XXL”;i:5;s:4:”XXXL”;}}}i:2;a:5:{s:4:”type”;s:4:”text”;s:8:”required”;s:0:””;s:5:”label”;s:16:”FLIGHT OUT No. 1″;s:4:”slug”;s:15:”flight-out-no-1″;s:5:”extra”;a:0:{}}i:3;a:5:{s:4:”type”;s:4:”date”;s:8:”required”;s:0:””;s:5:”label”;s:14:”Arrival Date 1″;s:4:”slug”;s:14:”arrival-date-1″;s:5:”extra”;a:0:{}}i:4;a:5:{s:4:”type”;s:4:”time”;s:8:”required”;s:0:””;s:5:”label”;s:14:”Arrival Time 1″;s:4:”slug”;s:14:”arrival-time-1″;s:5:”extra”;a:0:{}}i:5;a:5:{s:4:”type”;s:4:”text”;s:8:”required”;s:0:””;s:5:”label”;s:15:”FLIGHT IN No. 1″;s:4:”slug”;s:14:”flight-in-no-1″;s:5:”extra”;a:0:{}}i:6;a:5:{s:4:”type”;s:4:”date”;s:8:”required”;s:0:””;s:5:”label”;s:16:”Departure Date 1″;s:4:”slug”;s:16:”departure-date-1″;s:5:”extra”;a:0:{}}i:7;a:5:{s:4:”type”;s:4:”time”;s:8:”required”;s:0:””;s:5:”label”;s:16:”Departure Time 1″;s:4:”slug”;s:16:”departure-time-1″;s:5:”extra”;a:0:{}}i:8;a:5:{s:4:”type”;s:4:”text”;s:8:”required”;s:0:””;s:5:”label”;s:20:”Full Name of Guest 2″;s:4:”slug”;s:20:”full-name-of-guest-2″;s:5:”extra”;a:0:{}}i:9;a:5:{s:4:”type”;s:6:”select”;s:8:”required”;s:0:””;s:5:”label”;s:9:”T-Shirt 2″;s:4:”slug”;s:9:”t-shirt-2″;s:5:”extra”;a:1:{s:7:”options”;a:6:{i:0;s:5:”Small”;i:1;s:6:”Medium”;i:2;s:5:”Large”;i:3;s:2:”XL”;i:4;s:3:”XXL”;i:5;s:4:”XXXL”;}}}i:10;a:5:{s:4:”type”;s:4:”text”;s:8:”required”;s:0:””;s:5:”label”;s:17:”FLIGHT OUT No. 2 “;s:4:”slug”;s:15:”flight-out-no-2″;s:5:”extra”;a:0:{}}i:11;a:5:{s:4:”type”;s:4:”date”;s:8:”required”;s:0:””;s:5:”label”;s:14:”Arrival Date 2″;s:4:”slug”;s:14:”arrival-date-2″;s:5:”extra”;a:0:{}}i:12;a:5:{s:4:”type”;s:4:”time”;s:8:”required”;s:0:””;s:5:”label”;s:14:”Arrival Time 2″;s:4:”slug”;s:14:”arrival-time-2″;s:5:”extra”;a:0:{}}i:13;a:5:{s:4:”type”;s:4:”text”;s:8:”required”;s:0:””;s:5:”label”;s:15:”FLIGHT IN No. 2″;s:4:”slug”;s:14:”flight-in-no-2″;s:5:”extra”;a:0:{}}i:14;a:5:{s:4:”type”;s:4:”date”;s:8:”required”;s:0:””;s:5:”label”;s:16:”Departure Date 2″;s:4:”slug”;s:16:”departure-date-2″;s:5:”extra”;a:0:{}}i:15;a:5:{s:4:”type”;s:4:”time”;s:8:”required”;s:0:””;s:5:”label”;s:16:”Departure Time 2″;s:4:”slug”;s:16:”departure-time-2″;s:5:”extra”;a:0:{}}}

  • Solved

    CPT Select Field, AJAX Update Another and Show in Admin?

    Hello,

    I’ve been trying to solve this for a bit and can’t quite seem to get it working. I’m trying to make a CPT (Exams) where, after adding a new post, the Admin user selects a “Level” 1-5 (a ACF select field) and then some AJAX runs, collects some Questions (from a separate CPT) and then updates a “Questions” field on the Exam with the Post IDs of each Question.

    My problem seems to lie with programmatically assigning the Post IDs of the Questions to the Post Object field that is on the Exam.

    Here’s exactly what I’m doing: I’m going to “Add Exam”, selecting my “Level” (e.g. Level 1), clicking a button to run the AJAX, collecting the “Question” IDs, using update_field() to update the database value and then returning the IDs back to my new Exam post. I’ve checked the database after update_field is run in the AJAX and the Questions show up in the database, but if I Publish my Exam, the database questions get cleared out (because they don’t exist in the backend field).

    Here is my Javascript being run on the Exam CPT Admin:

    if( jQuery('body').hasClass('post-type-exams') ) {
    	//On Level Select, Run AJAX to Create Exam, store Question IDs (in Exam post) and then Generate the two PDFs
    	acf.addAction('ready', function(){ 
    		acf.unload.active = false;
    		var examID = acf.get('post_id'),
    			levelSelected = $('select#acf-field_5c9b8594fdf79').val();
    
    			$('div.acf-field-select.acf-field-5c9b8594fdf79').append('<div class="examOutput"><a href="#" class="button submitExam">Create Exam</a></div>');
    			$('a.button.submitExam').on('click', function(e) { //On Level Select Change
    				e.preventDefault();
    				//Loading Message
    				$('div.examOutput').html('<p class="examButtons">Creating Exam...
    ');
    				//Get Level Submitted
    				selectedExamLvl = $('select#acf-field_5c9b8594fdf79').val();
    				if( selectedExamLvl ) {
    					var examData = {
    						'action' : 'get_questions_for_exam', // the function name used in functions.php
    						'selectedExamLvl' : selectedExamLvl,
    						'examID' : examID
    					};
    					$.post(ajaxurl, examData, function(response) {
    						//$('#acf-field_5c9b994d45a1a-input').val(response).trigger('change');
    						var $question = $('select#acf-field_5c9b994d45a1a');
    							$question.focus();
    							$question.select2(response);
    
    						console.log(response);
    					}, "json"); 
    				}
    			});
    
    	});
    }

    Here’s the function it communicates with in functions.php:

    add_action( 'wp_ajax_get_questions_for_exam', 'get_questions_for_exam');
    add_action( 'wp_ajax_nopriv_get_questions_for_exam', 'get_questions_for_exam');
    function get_questions_for_exam() {
    	$examID = intval( $_POST['examID'] );
    	$examSelectedLevel = intval( $_POST['selectedExamLvl'] );
    
    	$modPrecent = array();
    	//Each Level has some Modules as well, this just collects them from an Options page
    	if(have_rows('level_' . $examSelectedLevel . '_modules', 'option')): //Repeater Name
    		while(have_rows('level_' . $examSelectedLevel . '_modules', 'option')): the_row();
    			$module = get_sub_field('module_number');
    			$percentage = get_sub_field('percentage_of_questions');
    			$modPrecent[$module] = $percentage;
    		endwhile; 
    	endif;
    
    	$questions = array();
    	//For Each Module in this Level, get the Requisite Number of Questions
    	foreach( $modPrecent as $mod => $percent ):
    		$questPerModule = get_random_questions($examSelectedLevel, $mod, $percent);
    		foreach( $questPerModule as $questID ) //Force Each Question into one big array (versus groups of arrays)
    			$questions[] = $questID;
    	endforeach;
    
    	//Update Questions Post Object field on Exam with Questions
    	update_field('field_5c9b994d45a1a', $questions, $examID);
    
    	echo json_encode($questions);
    
    	wp_die();
    }

    Anyone have any ideas?

  • Solved

    Repeater Field – Grids

    Hi All,

    I am trying to create a events grid using repeater fields that contain mostly text boxes and am having issues with the content showing up columns rather than rows. Below is an example of what I want to achieve and the php/css code.

    Thanks

    <?php
    // check if the repeater field has rows of data
    if( have_rows(‘new_event’) ):

    // loop through the rows of data
    while ( have_rows(‘new_event’) ) : the_row();
    ?>

    <div style=”background-color:<?php the_sub_field(‘box_background_color’); ?>” class=”careers-events-box”>

    <h2 class=”events-title”><?php the_sub_field(‘events_title’); ?></h2>

    <p>Date:</p><p><?php the_sub_field(‘events_date’); ?></p>
    <p class=”events-title-text”>Time: </p> <p><?php the_sub_field(‘events_time’); ?></p>
    <p class=”events-title-text”>Location: </p> <p><?php the_sub_field(‘events_location’) ?></p>
    <p class=”events-title-text”>Details: </p> <p><?php the_sub_field(‘events_details’) ?> </p>

    </div>

    .careers-events-box {
    width: 300px;
    height:300px;
    border-bottom-color:red;
    border-bottom-style: solid;
    display: flex;

    }

    .careers-events-box h2 {
    color:white;
    text-align: left;
    padding-left:5px;
    margin:0px;
    }

    .careers-events-box p {
    color:white;
    text-align: left;
    padding-left:5px;
    }

  • Solving

    Only showing 2 of 3 items in Post_Object Repeater

    Hi there,
    I’ve got an odd problem here (I think). I’m using a Repeater field to choose post objects from a CPT. When I go to echo the items saved to the repeater within the body of my page, it echos all 3 just fine and dandy. But when I use the exact same code within my header to echo those items to the nav bar, it’s only showing the most recent 2. When I do a print_r for those nav items, it only shows two, but seems to indicate that there are 3 (unless I’m understanding the output wrong). And when I query for the number of rows in that repeater in order to set the correct CSS, it’s definitely seeing all 3.

    Here’s the code within the body that’s showing all 3 items just fine:

    if( get_field('home_or_on_tour', 'option') == 'tour' ): ?>
    
    Please choose the location you wish to attend
    
    <?php if( have_rows('locationsdates', 'option') ):
    
     	// loop through the rows of data
        while ( have_rows('locationsdates', 'option') ) : the_row();
    
            // display a sub field value
            $post_id = get_sub_field('location', false, false);
            
            if($post_id): ?>
            <a href="<?php echo get_the_permalink($post_id); ?>"><?php echo get_the_title($post_id); ?></a>
            Event Date: <?php the_field('event_date', $post_id); ?>
            <?php $featured_img_url = get_the_post_thumbnail_url($post_id,'thumbnail'); ?>
            <img src="<?php echo $featured_img_url; ?>">
            <?php echo $post_id ?>
    
            <?php endif;
    
        endwhile;
    
    	else :
    
        // no rows found
    
    endif;
    
    endif; ?>

    Here’s the code for the CSS that’s working (I’m counting the rows in order to divide the nav bar area by the correct number of items)

    if( get_field('home_or_on_tour', 'option') == 'tour' ):
    				//$location = get_sub_field('location');
    				if( have_rows('locationsdates', 'option') ): the_row();
    				$count = count(get_field('locationsdates', 'option'));
    				//	$locationcount = count($location);
    			?>
    			@media (min-width: 768px) {
    				.navbar-right li {
    					width: -webkit-calc(100% / <?php echo $count; ?>); /** Safari 6, Chrome 19-25 **/
    					width: -moz-calc(100% / <?php echo $count; ?>); /** FF 4-15  **/
    					width: calc(100% / <?php echo $count; ?>); /** FF 16+, IE 9+, Opera 15, Chrome 26+, Safari 7 and future other browsers **/
    				}
    			}
    				<?php endif;
    			endif;

    And here’s the code for the nav bar, which is only giving me 2 of the 3 items:

    if( get_field('home_or_on_tour', 'option') == 'tour' ):
    										if( have_rows('locationsdates', 'option') ): 
    											while( have_rows('locationsdates', 'option') ): the_row();
    											
    												$location_id = get_sub_field('location', false, false);
    											
    												if($location_id): //$l=0;
    													$location = $location_id;
    													
    													setup_postdata( $location );
    									?>
    									<li><a href="<?php echo get_the_permalink($location_id); ?>" title="<?php echo get_the_title($location_id); ?>" ><?php echo get_the_title($location_id); ?></a></li>
    												<?php wp_reset_postdata();
    												endif;
    											endwhile;
    										endif;
    									endif;

    I’ve tried it without the setup_postdata/wp_reset_postdata() and get the exact same results. I’ve tried putting the nav query inside a regular wp loop (obviously didn’t work).

    When I do a print_r, I get this:

    <pre>string(3) "239"</pre>
    <pre>string(3) "240"</pre>

    The item not showing is “238”.

    I’ve now wasted at least 3 hours trying to figure out what I’m doing wrong, and am hoping that someone here will see immediately what I’m not seeing.

    Thanks in advance.

    ~Laura

  • Helping

    prevent remove or edit fields after update post

    Dear Friends,
    I have a repeater field ” Message Content “, i need that a user role can add row and fill it, but after updating post he couldn’t remove or edit filled row. it will use as a reporting system.

    How can i do it ?

    Thanks

  • Solving

    Combine dates between repeater field

    Hi !

    I have a question :

    I have a custom post type “theater_shows” with a repeater field “representations” and a datepicker subfield “date_representation”.

    I want to create an event page which display my representations grouped by dates of the datepicker’s subfield. For example, if I have two shows with the same date, I just want display the date one time.

    Actually, I have :

    Date 1
    Show 1

    Date 1
    Show 2

    and I would like :

    Date 1
    Show 1
    Show 2

    Did anyone ever do that? Is it possible?
    thanks !

  • Solved

    ACF reapeater optimizations

    Hi,

    About the John Huebner article https://acfextras.com/dont-query-repeaters/
    I am using repeater and i don’t see another way to do. So please could you tell me how to optimize ?
    Thanks

    Usage: Event with multiple date, hour , localtisation

    CPT EVENT
    ACF reapeater with DATE + HOUR + LOCALISATION

  • Unread

    Importing Repeater Fields within WP-CLI

    I can import no problem using something like this

    $meta = array( 'title' => 'This is a title' );
    $command = "post create --porcelain --post_type=event --post_status=publish --post_title='" . $event['TITLE'] . "' --meta_input=" . escapeshellarg( json_encode( $meta ) ) . "";

    I am trying to import data for repeater fields, but it’s not working. Here are some examples of things I tried.

    $meta = array(
    	'title' => 'title',
    	'date_times' => array( 'start' => '2018-04-21 16:25:36', 'end' =>'2018-06-21 16:25:36' ),
    );
    $command = "post create --porcelain --post_type=event --post_status=publish --post_title='" . $event['TITLE'] . "' --meta_input=" . escapeshellarg( json_encode( $meta ) ) . "";
    $meta = array(
    	'title' => 'title',
    	'date_times_0_start' => '2018-04-21 16:25:36',
    	'date_times_0_end' => '2018-04-25 16:25:36',
    );
    
    $command = "post create --porcelain --post_type=event --post_status=publish --post_title='" . $event['TITLE'] . "' --meta_input=" . escapeshellarg( json_encode( $meta ) ) . "";

    Is this possible to use WP-CLI to import data into a repeater field?

    Thank you!

  • Solved

    Show events if there's a date for today in a repeater

    I’m struggling wrapping my head around this scenario:

    I have an “event” post type and those “events”, for the topic of this thread, have three key fields:

    • A Date field for the “Start date” (data_inizio_evento)
    • Another Date field for the “End date” (data_fine_evento)
    • A Repeater field with these subfields (tabella_spettacoli):
      • A DATE field for the “Day of the spectacle” – get_sub_field(‘data_spettacolo’)
      • A TIME field for the “Time of the spectacle” – get_sub_field(‘orario_spettacolo’)
      • A “SELECT” field for the room where the spectacle takes place – get_sub_field(‘sala_spettacolo’)

    I’ve created a shortcode for displaying the events for TODAY and it “kind-of” works, i mean, it can select only the events that happens today and show the times of the today’s shows if available:

    <?php
    
    // create shortcode to list Today's events
    add_shortcode( 'eventi-oggi', 'protorob_eventi_oggi' );
    
    function protorob_eventi_oggi( $atts ){
    
        ob_start();
    
        //shortcode attributes
    
        extract(shortcode_atts(array(
            'type' => 'eventi',
            'sala' => '',
            'posts_per_page' => '-1'
        ), $atts));
    
        //query
        date_default_timezone_set( 'Europe/Amsterdam' );
        $oggi = date('Y-m-d');
    
        $oggiOptions = array(
            'post_type' => $type,
            'sala' => $sala,
            'posts_per_page' => $posts_per_page,
            'meta_query'=> array(
                'relation' => 'AND',
                array(
                  'key' => 'data_inizio_evento',
                  'compare' => '<=',
                  'value' => $oggi,
                  'type' => 'DATE'
                ),
                array(
                  'key' => 'data_fine_evento',
                  'compare' => '>=',
                  'value' => $oggi,
                  'type' => 'DATE'
                )
            ),
            'order'             => 'ASC',
            'orderby'           => 'meta_value',
            'meta_key'          => 'data_inizio_evento',
            'meta_type'         => 'DATE'
        );
    
        //
    
        $oggiEventQuery = new WP_Query( $oggiOptions );
    
        // This is for displaying today's date
        $oggiform = ucfirst( date_i18n('l, j F Y') );
        echo '<h2 style="text-align:center;">Programmazione ' . $oggiform . '</h2>';
        
        //If there's events for today, display the events
    
        if ($oggiEventQuery->have_posts()) {
    
            echo '<div class="grid-container grid-parent">';
    
    	    while ($oggiEventQuery->have_posts()): 
    	    //The post:
            $oggiEventQuery->the_post(); 
            //Getting some custom fields fr display
            $periodo = get_field('periodo_evento');
            $tabSpett = get_field('tabella_spettacoli');
            $image = get_field('locandina_evento'); 
            //Printing the stuff
            echo '<div class="grid-33">';
            //Show the thumbnail
            if( !empty($image) ):
                echo '<div class="thumb-spettacolo-oggi">';
                echo '<a href="';
                echo the_permalink();
                echo '">';
                echo '<img src="' . $image['url'] . '"/></a></div>';
            endif;
    
            // The Event title
    
            echo '<h3 class="titolo-evento-oggi">' . the_title('','',false) . '</h3>';
            // Display the spectacles times for that day:
    
            if ( have_rows('tabella_spettacoli') ) :
                while (have_rows('tabella_spettacoli')) :
                    the_row();
    
                    //Row Contents
    
                    $dataSpett = get_sub_field('data_spettacolo');
                    $oraSpett = get_sub_field('orario_spettacolo');
                    $salaSpett = get_sub_field('sala_spettacolo');
    
                    //Display only the times for today
                    if ($dataSpett == $oggi) :
                        echo '<span class="orario-singolo '. strtolower(str_replace(' ', '', $salaSpett)) .'"> ' . $oraSpett . ' - ' . $salaSpett . '</span>';
                    endif;
    
                endwhile;
            endif;
    
            echo '</div>';  
    
        endwhile;
    
        echo "</div>"; 
    
        wp_reset_postdata();
    
        $myvariable = ob_get_clean();
        return $myvariable;
    
        }else{
            echo '<h3>Non ci sono eventi in programma per oggi :-( </h3>';
        }   
    }
    
    ?>

    Now, the problem:

    Using that logic If there’s no spectacles for today they will show the same because I’m querying the posts based on the Start date and the End date.

    Is there a way to include the repeater “tabella_spettacoi” subfield in the query so I can show the events only if they have a subfield with a date/time for today? Thus avoiding showing events without spectacles for today?

    Thanks in advance.

  • Helping

    Simply query using a sub field as the meta_key

    This is my first go at querying based on ACF and I’m hitting a little mental snag. I have a custom post type set up with a bunch of fields using ACF pro. I want to be able to query on a sub field. Not within a repeater, just a subfield. Here is the structure:

    event post_type
    date_time
    start_date (set with picker and stored as mm/dd/yyyy)

    Here is what I would assume would work if I wanted to find all all events with a start date of today or later, but it doesn’t work.

    $args = array(
    ‘post_type’ => ‘event’,
    ‘meta_key’ => ‘date_time_%_start_date’,
    ‘value’ => date(‘mmddyyy’),
    ‘type’ => ‘DATE’,
    ‘compare’ => ‘>=’
    );

    I’m sure I’m missing something simple. I have a couple other straightforward queries that need to be structured as well. One problem (maybe) is that all my fields are structured like_this and I don’t know if the multiple underscores will throw off a sub field search.

    Thanks for the help with a new guy, I appreciate it.

  • Unread

    Get date value in strtotime only from last row of a reapeater

    Hello,

    Here is a part of a template I have problem with.

    I query an event custom post type, that contain a date repeatear. I check each value from date to only display events that will occur in futur. The following loop will display “something” many time from the main event unfortunatly but only want it displayed once.

    if( $listing_post->have_posts() ){
    	$dateformat = "YmdHi";
    	$actualdate = current_time( $dateformat );
    	if( have_rows('event_openhours') ):
    		while (have_rows('event_openhours') ) : the_row();
    			$eventendate = strtotime(get_sub_field('event_date_end', false, false));
    			$eventendate = date_i18n($dateformat, $eventendate);
    			// eventdate is set
    			// if ending date is ≥ actual date we display post
    			if($actualdate < $eventendate) :
    				echo "something";
    			endif;
    		endwhile;
    	endif;
    endif;

    I found a kind of solution :

    
    $dateformat = "YmdHi";
    $actualdate = current_time( $dateformat );
    $repeater = get_field('event_openhours');
    $last_row = end($repeater);
    $eventendate = $last_row['event_date_end'];
    if($actualdate < $eventendate) :
    	echo "something";
    endif;
    

    Which could replace the if / while and only check value from last reapeater value, but the problem I get is $eventdate only return a text value from the date picker. How can I translate it to a “YmdHi” format ?
    Actually $actualdate and $eventdate are in different format.

    Thank you for your help.

  • Helping

    Return all repeater rows containing a sub field which satisfies a condition

    I want to retrieve all the repeater rows that contain a specific subfield. I have a variable date field defined as follows :
    $journey_value = $_GET['onward-date'] != '' ? $_GET['onward-date'] : '';

    The “event_bus_date” is also a date field and both $journey_value and event_bus_date are in same date format.I have the following code but it displays nothing :

    <?php if( have_rows('event_instance') ): ?>
                <ul>
                  <?php while( have_rows('event_instance') ): the_row(); ?>
    			    <?php if($journey_date == the_sub_field('event_bus_date')) { ?>
                     <li><?php the_sub_field('event_bus_date'); ?></li>
    			    <?php } ?>
                  <?php endwhile; ?>
                </ul>
              <?php endif; ?>

    Please help to find the error in the code! Thank you

  • Unread

    Best way to use acf to store a user list to a post

    I’m kind of figuring out the best way to implement a list of users to associate with a post.

    Put kind of simply, i have some posts (events) that need to have associated a list of users (inscribed and paid/unpaid).

    My first thought was to create a field repeater, and increase in the backend or add a new line with the update_sub_field.

    My problem is when getting user info, i would need to search all the posts/events and check by user id if they are present, not very resource friendly.

    Thought the other way around, associate the user with the event and this might be the best approach.

    Now what acf option should i use to manage this field without “direct” handle by the end user and easy manageable to me?

  • Unread

    Filter Archive.php pages

    My need is to create a category filter in the archive.php wordpress file, to filter recipes on that page, or combine them with other category or ingredients on a recipes blog. I access on the archive.php page, clicking on a ingredient in a recipes and the url of that page is home_url/recipe-with/ingredient/ Now on that page I’ve added this code from ACF tutorials

     <div id="archive-filters">
    <?php foreach( $GLOBALS['my_query_filters'] as $key => $name ): 
    
    // get the field's settings without attempting to load a value
    $field = get_field_object($key, false, false);
    
    // set value if available
    if( isset($_GET[ $name ]) ) {
    
        $field['value'] = explode(',', $_GET[ $name ]);
    
    }
    
    // create filter
    ?>
    <div class="filter" data-filter="<?php echo $name; ?>">
        <?php create_field( $field ); ?>
    </div>
    
    <?php endforeach; ?>
    </div>
    
    <script type="text/javascript">
    (function($) {
    
        // change
        $('#archive-filters').on('change', 'input[type="checkbox"]', function(){
    
        // vars
        var url = '<?php echo home_url('property'); ?>';
            args = {};
    
        // loop over filters
        $('#archive-filters .filter').each(function(){
    
            // vars
            var filter = $(this).data('filter'),
                vals = [];
    
            // find checked inputs
            $(this).find('input:checked').each(function(){
    
                vals.push( $(this).val() );
    
            });
    
            // append to args
            args[ filter ] = vals.join(',');
    
        });
    
        // update url
        url += '?';
    
        // loop over args
        $.each(args, function( name, value ){
    
            url += name + '=' + value + '&';
    
        });
    
        // remove last &
        url = url.slice(0, -1);
    
        // reload page
        window.location.replace( url );
    
    });
    
    })(jQuery);
    </script>

    and in the child functions.php I’ve added that code

        // array of filters (field key => field name)
    $GLOBALS['my_query_filters'] = array( 
        'recipe_category'   => 'Recipes', 
    );
    
    // 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'   => 'IN',
            );
    
        } 
    
        // update meta query
        $query->set('meta_query', $meta_query);

    This generates that url when I go to check some category

    https://www.blogurl.com/property?Recipes=84,107

    and the page is a not found one without possibility to go back to the previous. Then another problem is that if I add a sub_fields of a custom field in the function.php I can’t show it, in particula I need to show ingredient_name (Text) from ingredients (Repeater). I tryed ingredients_ingredient_name but it doesn’t work. If Text type is not good, I’ve also under reapeater the ingredient_obj (taxonomy) that can be useful in the url, but I will need to show ingredients name in the filter. In the end I’d like also that the no result page, allow to deselect the filter that bring to the no result, and come back to the previous results. Or if this is not possible, come back simply with browser. This now don’t work.

    Theese Are the Custom Fields: Recipes Category

    {
                "key": "field_5752b4d33d004",
                "label": "Recipe Category",
                "name": "recipe_category",
                "type": "taxonomy",
                "instructions": "",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "33%",
                    "class": "",
                    "id": ""
                },
                "taxonomy": "category",
                "field_type": "checkbox",
                "allow_null": 0,
                "add_term": 1,
                "save_terms": 1,
                "load_terms": 1,
                "return_format": "id",
                "multiple": 0
            },

    Ingredients Parent with OBJ and Name subfields

    {
                "key": "field_5585b695453f5",
                "label": "Ingredients",
                "name": "ingredients",
                "type": "repeater",
                "instructions": "",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "",
                    "id": ""
                },
                "collapsed": "field_5620350d903a1",
                "min": 0,
                "max": 0,
                "layout": "table",
                "button_label": "Add Ingredient",
                "sub_fields": [
                  {
                        "key": "field_5620350d903a1",
                        "label": "Ingredient",
                        "name": "ingredient_obj",
                        "type": "taxonomy",
                        "instructions": "",
                        "required": 0,
                        "conditional_logic": [
                            [
                                {
                                    "field": "field_56206d699ae9c",
                                    "operator": "==",
                                    "value": "1"
                                },
                                {
                                    "field": "field_5588b2c5b4dc5",
                                    "operator": "!=",
                                    "value": "1"
                                }
                            ]
                        ],
                        "wrapper": {
                            "width": 20,
                            "class": "",
                            "id": ""
                        },
                        "taxonomy": "recipe_ingredient",
                        "field_type": "select",
                        "allow_null": 0,
                        "add_term": 1,
                        "save_terms": 1,
                        "load_terms": 0,
                        "return_format": "object",
                        "multiple": 0
                    },
                    {
                        "key": "field_5585317d9b50b",
                        "label": "Name",
                        "name": "ingredient_name",
                        "type": "text",
                        "instructions": "",
                        "required": 0,
                        "conditional_logic": [
                            [
                                {
                                    "field": "field_56206d699ae9c",
                                    "operator": "!=",
                                    "value": "1"
                                }
                            ],
                            [
                                {
                                    "field": "field_5588b2c5b4dc5",
                                    "operator": "==",
                                    "value": "1"
                                }
                            ]
                        ],
                        "wrapper": {
                            "width": 20,
                            "class": "",
                            "id": ""
                        },
                        "default_value": "",
                        "placeholder": "",
                        "prepend": "",
                        "append": "",
                        "maxlength": "",
                        "readonly": 0,
                        "disabled": 0
                    },

    So my needs are:

    • Generate a correct URL from this script to embed 2 or more custom fields.
    • Add sub_fields to that filter
    • Way to come back from No result page
  • Unread

    Auto populate Gravity Forms drop down

    Hi members

    I am still a beginner php coder and have exhausted all avenues to get this done and I really need help. I want to dynamically populate a Gravity Forms drop down list with the contents of an ACF field. The form I am testing on is a very simple form and not the very extensive one you can find on our website. Users need to register for online training courses and need to fill in the date the want to register but they don’t understand this and just fill in their own dates. We want to prevent this by giving them only the applicable dates to select from. There are more that 20 courses and I use the same form for each course. I got the “Course I want to attend” field to populate dynamically by using the form field options to capture the WordPress post title and put it into the field value. I want to do the same for the date field by putting the contents of the ul on the page generated by ACF repeater field into the drop down list. I cannot get this to work. I did the tutorial about how to put a list of post titles dynamically into the drop down form field but cannot get the ul list to do the same. I also tried some plugins but most are outdated or more expensive that AVADA theme I am using! Can someone please help me solve this problem? I will also post this on the Gravity Forms forum. See my attachment with the ACF code at the bottom as it is in my single.php WordPress file. (just a portion of the code applicable to the Johannesburg dates). I want to put the contents of number 1 into field number 2.

  • Unread

    Group repeater fields from different posts

    Apologies if this is a duplicate of my original post…it keeps getting deleted if you edit it more than once?

    Hey guys, I have done a bunch of searching and can’t seem to find a resolution particular to what I’m looking to do. Here’s what’s up:

    I created an event custom post type. Within each of those posts, are repeaters which allow the person to select multiple date and times. What I would like to do, and I’m not sure it’s possible the way I’m thinking, is group the events that have the same dates, by date.

    Something like this:

    Date 1

    • Event 1
    • Event 2
    • Event 3

    Date 2

    • Event 2
    • Event 3

    Date 3

    • Event 1
    • Event 2

    And so fourth and so on….

    While I’ve come across similar issues with potential resolutions, I’ve got nothing to work. Here’s how I’m handling my code:

    Outside the while loop:
    $current_header = '';

    Inside the while loop:

    $date_count = count(get_field('dates_times'));
                                        
    // Group events
    for ($i = 0; $i < $date_count; $i++) : 
    
        // Get repeater fields 
        $dates = 'dates_times_' . $i . '_date';
    
        // Snatch up the postmeta
        $temp_date = get_post_meta( get_the_ID(), $dates, true );
    
        // Convert Date
        $date = DateTime::createFromFormat('Ymd', $temp_date);
        if ( is_object($date) ) $day = $date->format('l - F, j');
    
        // Group by day
        if ( $day !=  $current_header ) :
            $current_header = $day;
            echo '<h2 class="medium-12 cell">' . $day . '</h2>';
        endif; 
    
        // REST OF POST CODE HERE
    
    endfor;

    This returns:

    Date 1

    • Event 1

    Date 3

    • Event 1

    Date 1

    • Event 2

    Date 2

    • Event 2

    Date 3

    • Event 2

    Date 1

    • Event 3

    And so on…. They’re not being grouped as expected. I assume the for loop is throwing them off. So any ideas or suggestions here would be greatly appreciated.

    Thanks.

  • Solved

    Date picker excluding past repeater fields

    Hi, hope someone can help on this.

    I’m using a date picker in a repeater to show events and want to not show events that are before the current date.

    I’ve got the date to show by using the CreateFromFormat within the repeater, but need to figure out an if statement that excludes past entries.

    Everything I’ve found refers to excluding dates from a post loop and not in a repeater, so a little stumped. This is my code for showing the date.

    <?php if( have_rows('academy_dates') ): ?>
    			<?php while( have_rows('academy_dates') ): the_row();
    
    				// vars
    
    				$datetime = DateTime::createFromFormat('j F, y',           get_sub_field('date'));
    				$date_day = $datetime->format('j');
    				$date_month = $datetime->format('F');
    				$date_year = $datetime->format('y');
    				$month = get_sub_field('month');
    				$location = get_sub_field('location');
    				$title = get_sub_field('title');
    				$content = get_sub_field('academy_description');
    
    				?>
    
    				<div class="academy-date">
    					<div class="academy-date-inner">
    						<div class="date"><?php echo $date_day; ?></div>
    						<div class="month"><?php echo $date_month; ?> '<?php echo $date_year; ?></div>
    						<div class="divider-line"></div>
    						<div class="academy-title"><?php echo $title; ?></div>
    						<div class="location"><i class="fas fa-map-marker-alt"></i> <?php echo $location; ?></div>
    						<div class="description"><?php echo $content; ?></div>
    					</div>
    				</div>
    
    			<?php endwhile; ?>
    		<?php endif; ?>

    Hope someone can help.

    Thanks
    Aaron

  • Solving

    List posts grouped by sub-field of repeater

    Hi,
    I wonder id anyone can help me on this issue:
    I have a custom post type (events) organised under 2 categories (past and current), each event has several occurrences managed with a repeater field (evento-paragens) with several sub-fields: event-date, event-hour, event-venue (this last one is a relational field).

    What I pretend is to list the events by occurrence and grouped by date:

    DAY 1
    HOUR — EVENT A — CITY
    HOUR — EVENT B — CITY
    HOUR — EVENT A — CITY
    HOUR — EVENT B — CITY

    DAY 2
    HOUR — EVENT A — CITY
    HOUR — EVENT B — CITY
    HOUR — EVENT A — CITY
    HOUR — EVENT B — CITY

    Until now what I could achieve was a list of all occurrences grouped by event:

    DAY 1 — HOUR — EVENT A — CITY
    DAY 1 — HOUR — EVENT A — CITY
    DAY 2 — HOUR — EVENT A — CITY
    DAY 2 — HOUR — EVENT A — CITY

    DAY 1 — HOUR — EVENT B — CITY
    DAY 1 — HOUR — EVENT B — CITY
    DAY 2 — HOUR — EVENT B — CITY
    DAY 2 — HOUR — EVENT B — CITY

    I’ve searched for a lot of forums but it seems that none of the examples suites my case. Maybe because the I need to group by a sub-field.

    Any ideas?
    M

  • Solved

    Sort admin by last value in repeater field

    Hi,

    I’m attempting to use pre_get_posts to sort a custom post type in the admin. The complication is that I want to use the first entry of a repeater field to do this.

    I have a repeater field attached to my post type called event_dates, inside that field I have a date field called event_dates_date along with some others like event_date_price and event_date_description. The event_dates_date field I am interested in returns the date as a Ymd string so I can sort them.

    The problem I have is that I can’t figure out how to target event_dates_date inside the event_dates repeater.

    add_filter('pre_get_posts', function ($query) {
        if ($query->is_admin) {
            if ($query->get('post_type') === 'event') {
                $query->set('orderby', 'meta_value');
                // Target the first instance of event_dates_date inside the event_dates repeater
                $query->set('meta_key', 'event_dates_date');
                $query->set('order', 'ASC');
            }
        }
        return $query;
    });

    Any pointers would be so very welcome!

  • Solved

    Events Calendar – Repeating Event Dates

    I’m building a basic events calendar and want to create repeating events by using a repeater field for which the user can select a date, adding as many as desired.

    The meta data is set out like this in the database;

    event_dates_1_repeat_date
    event_dates_2_repeat_date
    etc…

    How would I dynamically query these fields?

    $args = array(
       'post_type' => 'post',
       'posts_per_page' => -1,
       'order' => 'ASC',
       'orderby' => 'meta_value_num',
       'meta_key' => 'event_start_time',
       'meta_query' => array(
         'relation' => 'OR',
         array(
           'key' => 'event_date',
           'value' => $search_day
         ),
         array(
           'key' => 'event_dates_1_repeat_date',
           'value' => $search_day
         ),
         array(
           'key' => 'event_dates_2_repeat_date',
           'value' => $search_day
         )
       )
    );
  • Unread

    Filter Repeater rows by date field month range?

    Can anyone help with this, i’m not sure if its possible?

    I have a relationship field which acts as a month, each month has various events/dates within.

    When this is shown within the theme i only want it to show the current month and the following 5 months after no more, NOT any older months.

    Then when you’ve past the current month it adds another onto the list and the month just gone is not shown anymore?

    Kind of like a version of this wp_query which only shows the current date and those in the future…

  • Solved

    Disabled JS input (Select, User, …) Save as empty

    Hi all,

    I have several user roles on my website and depending on which role their have user can only see/edit a portion of form field (option page or custom post type). In order to easily change the edit rules, I add two settings for each field type “user_roles_can_see” and “user_roles_can_edit” with the “acf/render_field_settings” function.

    Exemple for the edit setting :

    add_action('acf/render_field_settings', 'edit_render_field_settings');
    
    function edit_render_field_settings( $field ) {
    	// Get all existing user role - managed in an option page
    	if (have_rows('roles', 'option')) {
    		while( have_rows('roles', 'option') ){
    			the_row();
    			$id_role = get_sub_field('id_role', 'option');
    			$choices[$id_role] = get_sub_field('nom_role', 'option');
    		}
    	}
    	// Add general choices
    	$choices['administrator'] = 'Administrateur';
    	$choices['all'] = 'Tous';
    	// Add the settings with dynamical choices
    	acf_render_field_setting( $field, array(
    			'type' => 'select',
    			'label' => 'Editable par',
    			'name' => 'user_roles_can_edit',
    			'instructions'	=> 'Select user role - Can edit the field.',
    			'required' => 0,
    			'default_value' => array('all'),
    			'choices' => $choices,
    			'multiple' => true,
    			'ui'			=> 1,
    	), true);
    }

    To disabled the field when user can’t edit it, I used the “acf/prepare_field” function (also used to return FALSE if user can’t see the field). I used the readonly setting and if needed ( JS field) I add a new wrapper class (to create a JS selector) and some JS to disabled the input.

    In exemple I turn all field type to text type and change the readonly setting. If the user can edit a repeater field I remove with JS the actions button :

    add_filter('acf/prepare_field', 'edit_prepare_field');
    
    function edit_prepare_field( $field ) {
    	global $current_user;
    	$current_role = $current_user->roles;
    	$type = $field['type'];
    	$wrapper = $field['wrapper'];
    	$width = $wrapper['width'];
    	$class = $wrapper['class'];
    	$name = $field['key'];
    	$value = $field['value'];
    	$choice = $field['choices'];
    	if (isset($field['user_roles_can_edit']) && !empty($field['user_roles_can_edit']) && is_array($field['user_roles_can_edit'])) {
    			foreach ($field['user_roles_can_edit'] as $role) {
    				if ($role != 'all' && !in_array($role, $current_role)) {
    					switch ($type) {
    						case 'repeater':
    							$class='disabled_repeater';
    							$field['readonly'] = 1;
    							$field['wrapper'] = array('width'=> $width,'class'=>  $class);
    							break;
    						default:
    							$field['type'] = 'text';
    							$field['readonly'] = 1;
    							break;
    					}
    				} elseif ($role = 'all' || in_array($role, $current_role)) {
    					$field['type'] = $type;
    					$field['wrapper'] = array('width'=> $width,'class'=>'');
    					$field['readonly'] = 0;
    					break;
    				}
    			}
    	}
    	return $field;
    }
    
    function read_only_field_javascript() {
    	if ( !is_admin() ) { return; } // applicable uniquement sur le wp-admin
    	?>
    	<script type='text/javascript'>
    		( function ( $ ) {
    		$( document ).ready( function () {
    			$('.disabled_repeater .acf-actions a[data-event="add-row"]').remove();
    			$('.disabled_repeater .remove a[data-event="add-row"]').remove();
    			$('.disabled_repeater .remove a[data-event="remove-row"]').remove();
    		});
    	  }( jQuery ) );
    	</script>
    	<?php
    }
    add_action( 'admin_footer', 'read_only_field_javascript' );

    This “tricks” works fine but I have a big issue with field type like : Select field type with advenced interface. If I disabled the select input :

    add_filter('acf/prepare_field', 'edit_prepare_field');
    function edit_prepare_field( $field ) {
    	...
    	case 'user':
    		$field['wrapper'] = array('width'=> $width,'class'=> 'disabled_user');
    		$field['readonly'] = 1;
    		break;
    	...
    	return $field;
    }
    
    function read_only_field_javascript() {
    	...
    	$('.disabled_user select').prop('disabled','disabled');
    	...
    }

    And save update when this field is disabled : I’ll have a empty value on the refresh page. (unlike for a date picker which works fine) I saw, Select field type with advanced interface is strangely coded (it’s not just a select input). So my question : How can I correctly disabled a JS advenced interface select field type (User, Select, Post object, etc.) in order to not change the database value when page is saved

    Thanks a lot to who may help (or juste took time to read).

  • Helping

    ACF query posts by date sub field

    Hello guys ! I’ve got a problem and i can’t find the answer anywhere.

    I’ve got a post_type called : show
    In this post type there is a repeater_field called : event
    And in this repeater_field there is a sub_field : start_date and start_time

    I would like to query all posts and get a result like this :

    17/04/2018 – 10:00 – Show 3
    18/04/2018 – 10:00 – Show 1
    18/04/2018 – 11:00 – Show 2
    18/04/2018 – 12:00 – Show 1

    Anyone can help me ?

  • Unread

    get_row_index() not returning to script in loop

    I’m trying to run a JS function for each repeater row. To do this, I figured I’d use et_row_index() to target each row. The function uses GSAP to animate a counter based on values input via ACF. My problem is the first loops row index (1) is repeated for each row even though each row is printing the row index properly and appending the correct element’s ID.

    This is my code:

    <?php if( have_rows('counters') ):?>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.4/TweenMax.min.js"></script>
    
    	<ul id="counter-wrap">
    		<?php while ( have_rows('counters') ) : the_row();?>	
    			<li class="single_counter" id="single-number-wrap-<?php echo get_row_index(); ?>">		
    			<?php if( have_rows('single_counter') ):?>
    				<?php while ( have_rows('single_counter') ) : the_row();?>	
    						<?php if(get_sub_field('prepend')):?>				
    						<span><?php the_sub_field('prepend');?></span>
    						<?php endif;?>
    						<span id="single-number-<?php echo get_row_index(); ?>"><?php the_sub_field('starting_number');?></span>
    						<?php if(get_sub_field('append')):?>				
    						<span><?php the_sub_field('append');?></span>
    						<?php endif;?>	
    						<div><?php the_sub_field('label');?></div>	
    												
    <script>
    jQuery( document ).ready(function($) {	
    		var Cont={val:'<?php the_sub_field('starting_number');?>'} , NewVal = '<?php the_sub_field('ending_number');?>' ;
    		var counter = $('#single-number-<?php echo get_row_index(); ?>')
    		TweenMax.to(Cont,3,{val:NewVal,roundProps:"val",onUpdate:function(){
    		  jQuery(counter)[0].innerHTML=Cont.val
    		}});
    });	
    </script>	
    							
    				<?php endwhile;?>
    			<?php endif;?>	
    			</li>			
    		<?php endwhile;?>
    	</ul>
    <?php endif;?>	
    
    And this is what is outputs:
    

    <script src=”https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.4/TweenMax.min.js”></script&gt;

    <ul id=”counter-wrap”>

    <li class=”single_counter” id=”single-number-wrap-1″>

    <span id=”single-number-1″>100</span>

    <span>M</span>

    <div>Likes and comments on instagram alone</div>

    <script>
    jQuery( document ).ready(function($) {
    var Cont={val:’100′} , NewVal = ‘300’ ;
    var counter = $(‘#single-number-1’)
    TweenMax.to(Cont,3,{val:NewVal,roundProps:”val”,onUpdate:function(){
    jQuery(counter)[0].innerHTML=Cont.val
    }});
    });
    </script>

    <li class=”single_counter” id=”single-number-wrap-2″>

    <span id=”single-number-1″>0</span>

    <span>M</span>

    <div>Press Coverage Impressions</div>

    <script>
    jQuery( document ).ready(function($) {
    var Cont={val:’0′} , NewVal = ‘9’ ;
    var counter = $(‘#single-number-1’)
    TweenMax.to(Cont,3,{val:NewVal,roundProps:”val”,onUpdate:function(){
    jQuery(counter)[0].innerHTML=Cont.val
    }});
    });
    </script>

    <li class=”single_counter” id=”single-number-wrap-3″>

    <span id=”single-number-1″>0</span>

    <span>K</span>

    <div>Attendees</div>

    <script>
    jQuery( document ).ready(function($) {
    var Cont={val:’0′} , NewVal = ‘4.5’ ;
    var counter = $(‘#single-number-1’)
    TweenMax.to(Cont,3,{val:NewVal,roundProps:”val”,onUpdate:function(){
    jQuery(counter)[0].innerHTML=Cont.val
    }});
    });
    </script>

    <li class=”single_counter” id=”single-number-wrap-4″>

    <span id=”single-number-1″>1000000</span>

    <div>Beers Distributed During Events</div>

    <script>
    jQuery( document ).ready(function($) {
    var Cont={val:’1000000′} , NewVal = ‘1389283’ ;
    var counter = $(‘#single-number-1’)
    TweenMax.to(Cont,3,{val:NewVal,roundProps:”val”,onUpdate:function(){
    jQuery(counter)[0].innerHTML=Cont.val
    }});
    });
    </script>

    <li class=”single_counter” id=”single-number-wrap-5″>

    <span>$</span>
    <span id=”single-number-1″>1000</span>

    <div>Paper Count</div>

    <script>
    jQuery( document ).ready(function($) {
    var Cont={val:’1000′} , NewVal = ‘2000’ ;
    var counter = $(‘#single-number-1’)
    TweenMax.to(Cont,3,{val:NewVal,roundProps:”val”,onUpdate:function(){
    jQuery(counter)[0].innerHTML=Cont.val
    }});
    });
    </script>

  • Solving

    Sort by repeater date picker field using if have rows

    I have a repeater called events.
    I use a date picker field called expire_on to hide the events if they have passed the expiration date.

    I would like to sort the events by the expiration date. Can someone help me modify my below code to do that? Thanks!

    <?php if (have_rows('events')): while (have_rows('events')) : the_row(); ?>
    
            <?php
            date_default_timezone_set('America/Los_Angeles');
            $today = date('Ymd');
            $expire = get_sub_field('expire_on');
    
            ?>
            <div class="events-row <?php if ($expire < $today) { ?>expired<?php } ?>">
              <h2><?php the_sub_field('events_title'); ?></h2>
              <h3><?php the_sub_field('events_date'); ?> | <?php the_sub_field('events_location'); ?></h3>
             </div>
    <?php endwhile; endif; ?>
Viewing 25 results - 51 through 75 (of 270 total)