Support

Account

Forum Replies Created

  • <?php $i = 0; while ( have_rows('publication_images', 148) ) : the_row(); $i++; if ($i != 1) : ?>
    											<div class="each-slide">
    										        <?php echo wp_get_attachment_image(get_sub_field('publication_each_image', 148), 'slider' ); ?>
    										    </div>
    										    ---
    										<?php endif; endwhile; ?>
  • I thought this would’ve worked… but doesn’t seem to do anything.

    <?php $i = 0; while ( have_rows(‘publication_images’, 148) ) : $i++; if ($i != 1) : the_row(); ?>
    <div class=”each-slide”>
    <?php echo wp_get_attachment_image(get_sub_field(‘publication_each_image’, 148), ‘slider’ ); ?>
    </div>

    <?php endif; endwhile; ?>

  • After many days, I managed to solve this (although no thanks to this support forum which seems almost deprecated now)

    As I am using ACF, I should use the built-in acf/save_post to do what I want after the data is saved. As this action will be called every time a post is created/saved, etc, I also needed to add an if statement to check if it’s the post type I’m looking for.

    All of the fields should be available via $_POST['fields'] as well if get_post_meta does not return what I’m looking for.

    The modified code below uses the ACF action AFTER the post has been saved, so the meta should be available. I can do a var_dump on the $_POST['fields'] to see what POST data is available as well.

    http://www.advancedcustomfields.com/resources/actions/acfsave_post/

    add_action('acf/save_post', 'people_postdata', 20);
    function people_postdata($post_id) {
    	global $wpdb;
    	if ( $post_id && (get_post_type($post_id) == 'People') ) {
    		$firstname = get_post_meta($post_id, 'first_name', true);
    		$lastname = get_post_meta($post_id, 'last_name', true);
    		$email = get_post_meta($post_id, 'email_address', true);
    		$password = get_post_meta($post_id, 'password', true);
    		$username = preg_replace('/[^A-Za-z0-9]/', '', strtolower(get_the_title($post_id)));
    	    $userargs = array(
    	    	'first_name' => $firstname,
    	    	'last_name' => $lastname,
    	    	'user_login' => $username,
    	    	'user_email' => $email,
    	    	'user_pass' => $password,
    	    	'role' => 'basic'
    	    );
    	    //var_dump($userargs);
    		wp_insert_user($userargs);
    	}
    }
  • Worked this out. @greenhoe hope this helps.

    // Create the frontend form
    function my_pre_save_post( $post_id ) {
    	if ( $post_id != 'new' ) {
    		return $post_id;
        }
        $post = array(
            'post_status' => 'draft',
            'post_title' => $_POST['fields']['field_5344021b6851b'],
            'post_type' => 'events'
        );  
        $post_id = wp_insert_post($post); 
        $_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );    
        return $post_id;
    }
    add_filter('acf/pre_save_post' , 'my_pre_save_post' );

    Now ACF allows a $_POST variable to be used for the title but does not really state how to use it. We create a title field in ACF and then used the field name that was automatically generated from ACF. So, as above:

    'post_title' => $_POST['fields']['field_5344021b6851b'],

    field_5344021b6851b is the name of my title field I created.

    Hope this helps. Worked for me. Let me know if you have any problems.
    -R

  • @greenhoe Is right – this also happens to me. And it no longer actually creates the post either. And actually the only way to clear those form fields which stayed permanent was to delete the rows from the wp_options table. Weird, but definitely not the solution.

    All I need is the ability to add the post title.

  • Has $_POST['acf_nonce'] been fixed, Elliot?

  • Thanks junixvillacorta, okay this makes sense. I wonder why I can’t use the standard title field for this? Why do I have to create duplicate field for title? This means on my form, on the CMS end (not front-end) it’ll have to title fields.

  • Thanks for the reply, @junixvillacorta – so I have added this in (I did have this… but used your code now so we’re on the same page) but it still doesn’t seem to be saving the title…

    <?php $options = array(
    	'post_id' => 'new',
    	'html_before_fields' => '<input type="text" name="post_title" size="30" id="title" placeholder="Enter title here" autocomplete="off">',
    	'field_groups' => array(835),
    	'submit_value' => 'Submit your listing'
    ); ?>
    
    <div class="container_12">
    	<div class="prefix_3 grid_9">
    		<div class="submit-form-container">
    			<h2>Submit your listing</h2>
    			<?php acf_form($options); ?>
    		</div>
    	</div>
    </div>
    <div class="clear"></div>
    // Create the frontend form
    function ps_acf_save_post( $post_id ) {
        // Don't do this on the ACF post type
        if ( get_post_type( $post_id ) == 'acf' ) return;
    
        // Get the Fields
        $fields = get_field_objects( $post_id );
    
        // Prevent Infinite Looping...
        remove_action( 'acf/save_post', 'my_acf_save_post' );
    
        // Grab Post Data from the Form
        $post = array(
            'ID'           => $post_id,
            'post_type'    => 'events',
            'post_title'   => $fields['new_title']['value'],
            'post_status'  => 'draft'
        );
    
        // Continue save action
        add_action( 'acf/save_post', 'my_save_post' );
    
        // Set the Return URL in Case of 'new' Post
        $_POST['return'] = add_query_arg( 'updated', 'true', get_permalink( $post_id ) );
    }
    add_action( 'acf/save_post', 'ps_acf_save_post', 10, 1 );
  • Not sure how to delete a post, but please do.

  • And if you see in the image below, where I have just print_r( $groups ) it needs to add all the arrays into one big array, then sort it.

  • I think it needs to sort all the names, before it adds the first letter…

  • Hi @elliot

    Many thanks for your help.

    This hasn’t outputted as expected. Looks like there’s both last name and last name for each artist (instead of first/last) and then it’s still not grouping all the Bs, all the Cs etc together.

    I managed to fix the first name/last name stuff, but it’s still not grouping.

    This is my full code below. Hope you can help, and many thanks for your help so far.

    <?php query_posts ( array ( 
    	'post_type' => 'programme',
    	'category_name' => 'archive',
    	//'meta_key' => 'last_name', 
    	//'orderby' => 'meta_value', 
    	//'posts_per_page' => -1, 
    	'order' => 'DESC' ) ); ?>
    
    <div class="container_12">
    	<div class="prefix_1 grid_10 suffix_1">
    		<?php while ( have_posts() ) : the_post(); ?>
    			
    			<?php 
    
    			$groups = array();
    			
    			if ( have_rows('artists') ) {
    				
    				while ( have_rows('artists') ) {
    					
    					the_row();
    					
    					
    					// vars
    					$first_name = get_sub_field('first_name');
    					$last_name = get_sub_field('last_name');
    					$first_letter = substr($last_name, 0, 1);
    					
    					
    					// add $first_letter holder to groups
    					if( !isset($groups[ $first_letter ]) ) {
    						
    						$groups[ $first_letter ] = array();
    						
    					}
    					
    					
    					// append artist to group
    					$groups[ $first_letter ][] = $first_name . ' ' . $last_name;
    					
    				}
    				
    			}
    			
    			// ouput
    			if( !empty($groups) ): ?>
    			
    				<?php foreach( $groups as $letter => $artists ) : ?>
    					
    					<h3><?php echo $letter; ?></h3>
    					
    					<?php foreach( $artists as $artist ): ?>
    						<p><?php echo $artist; ?></p>
    					<?php endforeach; ?>
    			
    				<?php endforeach; ?>
    				
    			<?php endif; ?>
    	
    		<?php endwhile; ?>
    	</div>
    </div>
    <div class="clear"></div>
    
    <?php wp_reset_postdata(); ?>
  • Thanks @elliot – I didn’t think it would be possible. Neat idea, I suppose… although could never probably work in practice. I had originally started with your solution, but changed it as I wasn’t too keep on a checkbox appearing on every page (as I need to sort the order and my tree hierarchy is a little complex) but I’ll think of something 🙂

    Thanks again and keep it up.

    -R

  • Quick question — why would this return each repeater on the page; but if I query the page from another template, for example

    <?php $animal_health = new WP_Query('post_type=page&p=126'); while ( $animal_health->have_posts() ) : $animal_health->the_post(); ?>

    it would only bring back one repeater… not all?

  • I worked it all out. Here is my solution.

    <?php if ( get_field('primary_and_secondary_selector') ) : ?>
     
    	<?php while ( has_sub_field('primary_and_secondary_selector') ) : ?>
    	
    	<div class="grid_3">
    	
    		<?php $primary_queries = get_sub_field('primary'); ?>
    		<?php if ( $primary_queries ) : ?>
    		
    			<?php foreach( $primary_queries as $primary_query ) : ?>
     
    				<?php echo wp_get_attachment_image(get_field('supplementary_logo', $primary_query->ID), 'medium' ); ?>
     
    			<?php endforeach; ?>
    			
    		<?php wp_reset_postdata(); ?>
    		<?php endif;?>
    		
    		<?php $secondary_queries = get_sub_field('secondary'); ?>
    		<?php if ( $secondary_queries ) : ?>
    		<ul>
    		<?php foreach( $secondary_queries as $secondary_query ) : ?>
     
    			<li><?php echo wp_get_attachment_image(get_field('supplementary_logo', $secondary_query->ID), 'medium' ); ?></li>
     
    		<?php endforeach; ?>
    		</ul>
    			
    		<?php wp_reset_postdata(); ?>
    		<?php endif;?>
    		
    		</div>
     
    	<?php endwhile; ?>
    
    	<?php endif;?>	
  • Okay, thanks for my friend Matt we managed to work this out.

    Basically, my PHP skills failed me a little as $date_passed was defined in an if statement, thus it’s not always defined and you are getting PHP notices when it is not defined.

    So, he suggested I either define $date_passed to something (null) or use isset or empty to check whether it has been defined.

    So adapting my code to below, worked:

    $date_passed = null;
    if ( $end_date_passed_check->format('Ymd') < date('Ymd') ) {
    $date_passed = 'date-passed';
    }

    I hope this post proves to be useful in applying specific classes to events that have passed using the ACF DatePicker.

    Full code as follows:

    <?php get_header(); ?>
    
    <?php if ( ! have_posts() ) : ?>
    
    <?php endif; ?>
    
    <div class="container_12">
     
    	<?php 
    	
    	while ( have_posts() ) : the_post(); 
    	
    	$end_date_passed_check = DateTime::createFromFormat('Ymd', get_field('event_end_date'));
    		
    	$date_passed = null;
    		
    	if ( $end_date_passed_check->format('Ymd') < date('Ymd') ) {
    		$date_passed = 'date-passed';
    	}
    	?>
    	
    	<div id="programme-<?php the_ID(); ?>" <?php post_class(); ?>>
    		<div class="grid_3">
    			<div class="each-programme-content <?php echo $date_passed; ?>">
    				<a class="each-programme-content-info" href="<?php the_permalink(); ?>">
    					<?php if ( get_field('type_of_event') ) : ?>
    						<span class="type-of-event"><?php the_field('type_of_event'); ?></span>
    					<?php endif; ?>
    					<?php if ( get_field('event_start_date') && get_field('event_end_date') ) : ?>
    						<?php $start_date = DateTime::createFromFormat('Ymd', get_field('event_start_date'));
    						$end_date = DateTime::createFromFormat('Ymd', get_field('event_end_date')); ?>
    						<h4 class="date"><?php echo $start_date->format('d'); ?>&mdash;<?php echo $end_date->format('d F'); ?></h4>
    					<?php elseif ( get_field('event_start_date') ) : ?>
    						<?php $start_date = DateTime::createFromFormat('Ymd', get_field('event_start_date')); ?>
    						<h4 class="date"><?php echo $start_date->format('d F'); ?></h4>
    					<?php endif; ?>
    					<h4><?php the_title(); ?></h4>
    				</a>
    			</div>	
    		</div>
    	</div>
    	
    	<?php endwhile; ?>
    
    </div>
    <div class="clear"></div>
    
    <?php get_footer(); ?>
  • Hi @rootshift,

    Just working through this with @elliot so close to a solution.

    Once this has been worked out, I’ll post up the solution.

    But basically, you should be able to do this for your button:

    <?php
    $event_end_date = DateTime::createFromFormat('Ymd', get_field('your_event_end_field'));
    		
    if ( $event_end_date->format('Ymd') < date('Ymd') ) { ?>
      <a href="#">Volunteer link</a>
    <?php } else { ?>
      Volunteering no longer available 
    <?php } ?>
  • Hi @elliot,

    Many thanks for your reply.

    I am testing this by echoing out both the current date and get_field('event_date_date') with the format Ymd with each event to compare using:

    echo $end_date_passed_check->format('Ymd');
    echo '<br/>';
    echo date('Ymd');

    These all seems to be correct, but what it seems to be doing is when the first if statement is true, then it applies it to the rest of the elements. I think this might be a while loop error, but maybe you can help?

    Here is what my output looks like http://goo.gl/xW3pwT

    Many thanks,
    R

  • Looks like it’s to do with the fact it’s in a while loop?

    while ( have_posts() ) : the_post();

  • And actually, I realised I hadn’t formatted the date, so have this now —

    $end_date_passed_check = DateTime::createFromFormat('Ymd', get_field('event_end_date'));
    		
    if ($end_date_passed_check->format('Ymd') < date('Ymd'))
    {
       $date_passed = 'date-passed';
    }

    But alas it’s adding the class randomly… not as it should be.

  • I thought this might’ve worked; but throwing out an undefined variable…

    $end_date_passed_check = DateTime::createFromFormat('Ymd', get_field('event_end_date'));
    	
    if ($end_date_passed_check < date('Ymd'))
    {
        $date_passed = 'date-passed';
    }

    <div class="each-programme-content <?php echo $date_passed; ?>"></div>

  • Okay, school boy error, missed the echos 🙁

    <a href="<?php echo get_permalink($course->ID); ?>"><?php echo get_the_title($course->ID); ?></a>

    Many thanks for the help.

  • And I did change

    the_permalink($course->ID)

    to

    get_permalink($course->ID)

    But made no difference…

  • Hi again @elliot

    Thanks for your continual help.

    My code now stands as this:

    <?php $courses = get_posts(array(
    			'meta_query' => array(
    				array(
    				'key' => 'short_course',
    				'value' => '"yes"',
    				'compare' => 'LIKE'
    				)
    			)
    		));
    		if ( $courses ) : foreach ($courses as $course) : ?>
    			<a href="<?php the_permalink($course->ID); ?>">test</a>
    		<?php endforeach; endif; ?>

    But the permalink isn’t bringing back the permalink URL… only the current page URL. Am I missing something?

Viewing 25 posts - 1 through 25 (of 26 total)