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:

        ?><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"); ?>
                                        	<a href="<?php the_field("presentation_download_file"); ?>" target="_blank" class="arrow">Download</a>

    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; ?>                                    
    			<?php the_content(); ?>   
    	           	<div id="presentations"> 
    <!-------------------CUSTOM WP_QUERY LOOP------------------------->                   	
    	                        // 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(
    						'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(); ?>
    					$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;
                                    <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"); ?>
    <!-------------------FIRST ACF RELATIONSHIP LOOP THAT BREAKS THINGS------------------------->                                  
    					#--------- 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 
    					#--------- presenters											
                                            $posts = get_field('presenters');                         
                                            if( $posts ): ?>
    						<?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 
                                        <?php echo $presentationAbstract; ?>
                                        	<a href="<?php echo $presentationDownloadFile; ?>" target="_blank" class="arrow">Download</a>
                                <?php endwhile; ?>                           
                            <?php endif;
                            // Reset Query
                            wp_reset_postdata(); ?>
    			</div><!-- / #presentations -->
                	</article><!-- article -->
        <?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:

  • 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.

    $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>
    <?php } ?>
    $linksResources = get_field('links_and_resources'); 
    if($linksResources) { ?>
        <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(){

    In your JS file:

    		type: "POST", 
    		data: 'action=getdatefunction',
    		cache: true, 
    		success: function(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 =;
    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. (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)