Support

Account

Forum Replies Created

  • By the looks of things, you don’t need ACF for this job. It’ll be a simple case of querying wordpress posts by category. I would post code for this but there’ll be tonnes of examples online if you Google “wordpress query posts by category”.

  • Try something like:

    if($image){
        ?><img src="<?php echo $image[0]; ?>" width="<?php echo $image[1]; ?>" height="<?php echo $image[2];?>" class="mbottom0"><?php
    } else { 
        ?><img src="errorpicture.jpg" class="mbottom0"><?php
    }
  • Right.

    I think the problem is that you’re resetting data for everything, so once that first relationship first is closed and the data is reset, the data from the parent loops gets reset also (possibly).

    Seeing as you are not using any ACF functions or anything too specific, just change the relationship codes to: 1) remove the setup_postdata, 2) use $post->post_title instead of the_title() and 3) remove the resets.

    EDIT: beat me to it

  • So i’m guessing it’s the following 2 field calls that are failing?

      <?php the_field("presentation_abstract"); ?>
                                        <p>
                                        	<a href="<?php the_field("presentation_download_file"); ?>" target="_blank" class="arrow">Download</a>
                                        </p>
                                    </section>	

    If this is the case then a work around would be simple, set those fields as variables further up the page, and then simply call the variable.

    <!-------------------MAIN PAGE LOOP------------------------->
      <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>  
    	
            <div id="main" class="clearfix">
    	               
    	        <?php if(trim(get_field("headline_override")) != ""): ?>
    	        	<h1><?php the_field("headline_override"); ?></h1>
    				<?php else: ?>
    	        	<h1><?php the_title(); ?></h1>
    	        <?php endif; ?>                                    
    	        <article>
    			<?php the_content(); ?>   
    	           	<div id="presentations"> 
                       	
                       	
    <!-------------------CUSTOM WP_QUERY LOOP------------------------->                   	
                       	
    				<?php
                        
    	                        // The Query
    	                        $args = array(
    	                            'post_type'	=> 'presentations',
    	                            'posts_per_page'     => -1,
    	                            'order' => 'DESC',
    	                            'orderby' => 'presentation_date',						
    	                            'post_status' => 'publish',
    					'meta_key' => 'presentation_date',
    					'meta_query' => array(
    						array(
    						'key' => 'archived_presentation',
    						'value' => 'true',
    						'compare' => '!='
    					)
    				)							
    	                        );						
                            $custom_loop = new WP_Query($args);			
                            #echo $custom_loop->request; 	
    						
    			$previous_year = "";						
                            
                            // The Loop
                            if( $custom_loop->have_posts() ): ?>
                                <?php while( $custom_loop->have_posts() ): $custom_loop->the_post(); ?>
                                	<?php 
    					$date = DateTime::createFromFormat('Ymd', get_field('presentation_date'));
    					$current_year = $date->format('Y');		
    					
    					if($previous_year != $current_year) { echo "<p>" . $current_year . "</p>";}
    					$previous_year = $current_year;
    				?>
                                    <section>
                                    <h2><a href="<?php the_field("presentation_download_file"); ?>" target="_blank"><?php the_title(); ?></a></h2>
                                       
    <?php $presentationDownloadFile = get_field("presentation_download_file");
    $presentationAbstract = get_field("presentation_abstract"); ?>
                                    <p>
    <!-------------------FIRST ACF RELATIONSHIP LOOP THAT BREAKS THINGS------------------------->                                  
    					<?php
    					#--------- research center
    					$posts = get_field('research_center');                         
    					if( $posts ): 
    						foreach( $posts as $post): // variable must be called $post (IMPORTANT)
    							setup_postdata($post); ?>
    							<strong>Lead Research Center:</strong> <a href="/about/#center-<?php echo $post->ID; ?>"><?php the_title(); ?></a><br />
    						<?php endforeach; 
    						wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly 
    					endif; 						
    					
    					#--------- presenters											
                                            $posts = get_field('presenters');                         
                                            if( $posts ): ?>
                                                <strong>Presenter(s):</strong>
    						<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT)
    	                                               setup_postdata($post); ?>
    	                                                <a href="/about/staff/#staff-<?php echo $post->ID; ?>"><?php the_title(); ?></a>
    	                                        <?php endforeach; 
                                                wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly 
                                            endif; 	                                    										
    										?>                                    
                                        </p>
                                        <?php echo $presentationAbstract; ?>
                                        <p>
                                        	<a href="<?php echo $presentationDownloadFile; ?>" target="_blank" class="arrow">Download</a>
                                        </p>
                                    </section>			                                                                                                     
                                <?php endwhile; ?>                           
                            <?php endif;
                            
                            // Reset Query
                            wp_reset_postdata(); ?>
                                                                                              		                     
    			</div><!-- / #presentations -->
                                                           
                	</article><!-- article -->
                </div> 
            </div>                                              
        <?php endwhile; ?>            

    p.s. I don’t really get what you are trying to do so I can’t comment on whether the nested loops are required or not, but I think for single pages your first loop shouldn’t be required. I might be wrong though πŸ˜‰

  • If that isn’t easiest for your users then surely a Repeater field would be easier for them? It may not be as visually attractive but it’ll certainly function better for your cause πŸ˜‰

    Hell, you can even reskin it to look like a Gallery if you want to.

  • For consistencies sake i’d probably just use two ACF wysiwyg fields. This of course does have it’s drawbacks, you can’t use the default the_content functions for starts and the_excerpt field doesn’t get created; but if you don’t need either of those then there’s no reason why using 2 ACF wysiwyg’s would be a problem.

  • Would it be possible to post your full-code? It’s impossible to troubleshoot your problem with the example, and it seems from your description that there may be no need for many nested loops. A more full description as to your goals would also be helpful.

    πŸ™‚

  • @elliot – it was a bit confusing for me at first, a little notice on the edit profile page about Gravatar for avatars would be a nice touch. Alternatively User Avatar is a nice simple plugin for avatar uploads for users πŸ™‚ (as a fallback)

  • Are you using a Wysiwyg field for a shortcode alone? Or is the field being used for content and shortcodes?

    If it’s shortcode only, you could try changing your Wysiwyg field to a standard text field, then use the following PHP to activate the shortcode this way:

    <?
    $shortcode = get_field('my_shortcode');
    echo do_shortcode($shortcode);
    ?>
    

    Untested, but should work.

  • Also you could refer to Using conditional statements on the following page: http://www.advancedcustomfields.com/resources/getting-started/code-examples/

  • First off, the_field is used to echo a field’s contents, get_field is used to retrieve the fields data into into a variable, or in your case, can be used in an if statement. You also have a semi-colon after an if statement which is invalid and an empty else may had well just be removed. I’ve tied up your code a bit, give it a try.

    
    <?php 
    $dlMaterials = get_field('downloadable_material'); 
    if($dlMaterials) { ?>
        <div class="material">
            <h4>Supplemental Material:</h4>
            <a href="<?php echo $dlMaterials; ?>"><i class="icon-download-alt"></i> - Download Supplemental Material</a>
        </div>
    <?php } ?>
    
    
    <?php 
    $linksResources = get_field('links_and_resources'); 
    if($linksResources) { ?>
        <h4>Resources:</h4>
        <p><?php echo $linksResources; ?></p>
    <?php } ?>
    
  • Haha, you’re experiencing basically everything I went through.

    This is because the user type isn’t allowed to access the WP uploader. Only admins are by default. I changed my site to allows editors to use the WP uploader. If you intend on logged out users being able to upload stuff through the WP uploader… well, be careful.

    Would like to hear Elliots opinion on allowing general public users access to image/file/gallery fields on front-end forms.

  • But what happens if I want to edit my contributions in 101 years time? πŸ˜‰

    It’s worth mentioning that when editing a post with code blocks, the slanted apostrophes get pushed back onto the line above, so you need to pad them down every time you edit. This may be the problem described above (has caught me out every time i’ve edited a post so far)

  • You mentioned when you loaded the .php file directly, does this mean this isn’t a part of a WordPress page? A stand-alone PHP page? I’m not sure whether ACF fields would be accessible through this or not, i’d guess not.

    You’d be better off adding a php callback function for your ajax in your functions.php file.

    Here’s a simple example of getting a field with AJAX:

    In your functions.php:

    
    add_action('wp_ajax_getdatefunction', 'getdate'); 
    add_action('wp_ajax_nopriv_getdatefunction', 'getdate'); 
    function getdate(){
    
       the_field('your_date_field');
    
       die();
    }
    

    In your JS file:

    
    $('button').click(function(){
    	$.ajax({
    		type: "POST", 
    		url:'/wp-admin/admin-ajax.php',
    		data: 'action=getdatefunction',
    		cache: true, 
    		success: function(results){
    			$('.your-date-container').html(results);
                            alert('The date is: '+results);
    		}
    	});
    });
    
  • The default setup doesn’t allow required sub-fields in Repeater fields I don’t think. This doesn’t mean to say you can’t come up with your own solution though.

    I’d approach this in either 2 routes:

    1) Create bit of jQuery that sits on the edit pages of WP and doesn’t allow the post to be Published until the required sub-fields are validated.

    2) Simply add conditional code to wherever you are using the sub-fields data to not output the element if the sub-field isn’t populated (I do this often for things like captions or titles in repeater fields)

    If you need help with the first bit of JS let me know as i’ve written something similar for a major project that required custom validation of ACF fields.

  • You’d be looking at a simple bit of jQuery like this (obviously you will have to change the selectors)

    
    currentSlide = $('.slider .active');
    nextSlide = currentSlide.next();
    prevSlide = currentSlide.prev();
    
    /** then to get for instance, a caption from inside the slides : *//
    nextSlideData = nextSlide.find('p.caption').html();
    prevSlideData = prevSlide.find('p.caption').html();
    
    alert('Next caption: '+nextSlideData+' & Previous caption: '+prevSlideData);
    
  • Well the project I used it on is an Ebay like system that allows users to pay to add listings to a luxury camp site database, so there’s tonnes of extra scripts I needed for the acf_form pages; I also amended the experience of ACF a lot (had to), rewriting the HTML for repeater fields and so on.

    I second your final sentence!

  • Hi Darpan,

    It seems like you are trying to show a page-specific field on every page on the site, would that be right?

    The Options Page extension will help you here. This allows you to display a field on any page of the site, added into one site-wide options page. This is the opposite of adding fields to pages, that’ll only be accessible when the page is being shown; hence why when you added the post ID to your code, it worked.

  • Glad you worked it out Jaace. On the site I built with a mass of front-end files I simply had two headers and footers. I used get_header and get_footer for all the normal pages, and set up two new duplicates but with lots of amended scripts for acf_form, called dash-head and dash-foot. Then I use call these like get_template_part(‘dash-head’) instead of get_footer().

  • I noticed πŸ˜‰ love it – any site that I can avoid sprites on these days simply makes me happy

    You’ve actioned already. Nice work

  • Anyone that stumbles across this post in need of help with importing a CSV of posts into WP, try out this plugin. It allows you to add columns for all of the default WP fields like the_title, the_content and so on. It also allows any custom fields to be added as columns, so ACF is completely compatible.

    In fact, you can even stick a repeater field into the CSV. I done this for a recent site.

    You’d have the columns like:
    repeater_0_text, repeater_1_text, repeater_2_text, repeater_3_text

    And then another just called ‘repeater’, with the amount of sub-fields (in this example, the value would be 4).

    Give it a try! Hope this helps someone one day.

    http://wordpress.org/plugins/csv-importer/screenshots/ (I know it’s old, but it works)

  • Erm, I just realised Custom Fields -> Settings doesn’t exist.

    Time for bed.

  • In fact a configurable option in Custom Fields -> Settings would probably make the most sense. And default it to sub-menus for all existing users πŸ™‚

  • Hi Jaace,

    First of all, do you have acf_form_head in your page, as well as acf_form?

    I built a site around 2 months ago that has a mass of front-end fields, text, radios, selects, gallerys, repeaters, etc. All of these worked fine. I do however remember having a lot of trouble whilst messing around with the Gallery field, it took a while to get working.

    If you need some more help give me a shout, i’ll let you look at the dev site and the code used to create the forms. roartex at me dot com

Viewing 24 posts - 1 through 24 (of 24 total)