Support

Account

Forum Replies Created

  • Your loop is definitely rolling around twice, as your HTML currently stands:

    <article id="blue" class="post-184 page type-page status-publish hentry">
    
        <div class="container">
    
            <div class="container">
    
                <div class="entry-header">
                    <h1 class="entry-title">TITLE</h1>
                </div>
                <div class="col-sm-6">
                    <h5>SUB-TITLE</h5>
                    <p>CONTENT</p>
                </div>
                <div class="col-sm-6">
                    <h5>SUB-TITLE</h5>
                    <p>CONTENT</p>
                </div>
    
            </div>
            
        </div>
    
    </article>

    The only reason for this would be if:

    if( have_rows('text_section') ): while ( have_rows('text_section') ) : the_row();

    was being called twice, because you had two rows in your field text_section. The first row must be empty, because it’s only calling in the containing <div class=”container”>, and then skipping everything else.

    The second one actually has some content in it, so it’s working correctly.

    The easiest way to error check this is just to surround the entire thing in a containing if check to make sure that all of the fields you have content in them (you could also set them as required in ACF, which would also solve this)

    It’s also worth using the variables that you’ve set at the beginning of the loop, rather than the get_sub_field calls for code cleanliness.

    <article id="blue" <?php post_class(); ?>>
    
    	<?php if( have_rows('text_section') ): while ( have_rows('text_section') ) : the_row();
    
    		// Call in content variables
    		$title  = get_sub_field('title');
    		$text   = get_sub_field('text');
    		$texts  = get_sub_field('text_copy');
    		$cols   = get_sub_field('columns');
    
    		// If Title & first column text & columns has been set and is not empty
    		if( $title && $text && $cols ) :
    
    	?>
    
    			<div class="container">
    
    				<div class="entry-header">
    					<h1 class="entry-title"><?php echo $title; ?></h1>
    				</div>
    
    				<?php
    				if($cols == "1") : ?>
    
    					<?php echo $text; ?>
    
    				<?php elseif( $cols == "2") : ?>
    
    					<div class="col-sm-6">
    						<?php echo $text; ?>
    					</div>
    					<div class="col-sm-6">
    						<?php echo $texts; ?>
    					</div>
    
    				<?php endif; ?>
    
    			</div>
    
    	<?php 
    
    		endif; //check title, text, and cols exist
    
    	endwhile; //per item in text_section loop
    	
    	endif; //if text_section has rows
    	
    	?>
    
    </article>
  • It looks like you’ve got an extra header+container being brought in as part of the loop, double check the code to make sure that it’s all definitely contained within those if statements.

    Equally, double check that you don’t have any ACF rows in your post that are empty but causing the loop to go round a couple of times.

  • I’ve solved a similar problem through the use of a Multi site installation and using the switch_to_blog() function to call in what I need.

    http://codex.wordpress.org/Function_Reference/switch_to_blog

    In my solution I had a CPT that I wanted to bring into each of my subdirectories and then give the site user the option to select which posts they wanted to see on their site. I think something similar to this would work for you, although as I’m remembering I think I did have to hack about a little to make it work properly.

    Without the hacky-bit in the backend, I would say the easiest method is the following:

    – Setup your site as a subdirectory multisite. You’ll still need to manually create the subdirectory sites, but if you’re going to have to manually setup the CNAMES and stuff anyway, then this doesn’t end up being too much additional work.

    – Clock the ID of the subdirectory.

    – Add a new CPT property post on the core site, with the details of the property. Within this post, add a new field for “multisite” in which you put the SiteID.

    – Make a new page in the multisite, set it as the homepage.

    – Make a child theme for all multisites to use with a front-page.php template with something like the following

    <?php
    
    get_header()
    
    $original_site_id = get_current_blog_id();
    
    switch_to_blog(1); // 1 is the root blog with all the CPT posts in
    
    $query_args = array(
    	'post_type'	=>  'properties',
    	'meta_query' => array(
    		array(
    			'key'     => 'property_site_id',
    			'value'   => $original_site_id,
    		),
    	),
    );
    
    $query = new WP_Query($query_args);
    
    // Continue with standard WP loop and properties output
    
    restore_current_blog(); // Important to do this for other template requirements in the footer
    
    get_footer();
    
    ?>

    That should then give you the option to show a multisite exclusively using ACF fields from your primary website that you can edit everything in one place in one go.

    In practice you can also use this to give each user their own contact forms, newsletter signups etc. which may or may not be useful in the future.

    I would also say that if you decide to give multisite sites ACF fields they need to fill out, it’s much more practical to export those and put them into the child-theme as external files, as they will be auto-created on each site for you.

    Hopefully that helps? 🙂

  • You can use the update_field function to put the post ID in outside of anything related to the ACF form:

    <?php update_field($selector, $value, $post_id); ?>

    $selector would be the field ID: field_57319b21314aa

    Depending on the rest of the setup I think would depend on how would be most effective to get that information into the form, whether it’s populated before or after you submit. It could be possible to use the WP pre_get_posts() hook or the acf/save_post hook, grab the post ID and then update the field with it in the relevant place.

  • Fields added via options pages are all saved and loaded in via ‘option’ as opposed to page id. As such, the only way to have two options pages with unique data is to make them each have unique slugs.

    https://www.advancedcustomfields.com/resources/register-multiple-options-pages/

    Once you’ve changed the slugs for the pages, you won’t be able to see the data any longer – so do keep it open in a tab or just c&p somewhere if it’s important to keep a record of it before changing.

    As to referencing this data, outside of having an if statement to check the post type and output the relevant options depending on the outcome, if you put the relevant post type at the beginning / end of the field name, you could reference this using the WordPress get_post_type function.

    get_field( get_post_type($post) . '_description', 'options' );

  • Headers can be tricky and are a common pitfall for spam filters if you are sending from an address that is different to the default site one. It should look a little bit like this however:

    $headers = 'From: Edd <[email protected]>;' . "\r\n";
    $headers .= 'Bcc: Admin <[email protected]>;' . "\r\n";
    
        wp_mail($to, $subject, $message, $headers);
  • This may be a bit flakey as i’m typing on a phone, but perhaps something like the following:

    $query_store_args = array(
        'post_type' => 'posts',
        'cat' => 'store',
        'posts_per_page' => -1
    );
    
    $query_store = new WP_Query($query_store_args);
    
    if( $query_store->have_posts() ) :
        while( $query_store->have_posts() ) : $query_store->the_post();
    
    // code I added above 
    
    endwhile;
    
    endif;

    Edit: forgot a line

  • Assuming i follow your meaning, you’d have to also wrap that snippet of code above with a WP_Query or query_posts call for all the posts that have table data. This could be quite simple if they’re all in one category or of a particular post type, otherwise you may need to get more specific with a meta query, which will allow you to specifically call in all posts that have the photo sub_field filled in, for example.

    If you can give me an idea of the specific heirarchy of the site setup or what the post type is called or the category name I can try to help with your specific query

  • I don’t know if it would cause a complete failure but in your image you use get_field(‘image’) instead of get_sub_field(‘image’).

    Otherwise at a first glance that looks like it’s all correct…

    Edit: Do double check that your image field especially, but that all your other fields are definitely outputting in the correct format. If your image field is outputting as ID locally but as an Array on live it’s an easy thing to miss but will mess everything else up

  • I think I see what you mean and what you’re trying to do. No you wouldn’t need to use an && check, but it is worth separating the checks and outputs to only the bits they need to control, which will make it a lot clearer for you.

    What I think you’re trying to do is output $text on the left and $texts on the right. However your IF statements are exclusively saying

    if $cols == 1 show me $text
    if $cols == 2 show me $texts

    Whereas what you want is:

    if $cols == 1 show me $text
    if $cols == 2 show me $text and show me $texts

    To adapt my code slightly above, this would be:

    <?php
    $title	= get_sub_field('title');
    $text	= get_sub_field('text');
    $texts	= get_sub_field('text_copy');
    $cols	= get_sub_field('columns');
    
    <?php
    // check if the flexible content field has rows of data
    if( have_rows('text_section') ):
    	while ( have_rows('text_section') ) : the_row(); ?>
    
    		<div class="entry-header">
    	        <h1 class="entry-title"><?php the_title(); ?></h1>
    	    </div>
    
    		if( get_row_layout() == 'blue_content_blocks' ) :
    
    			if( $cols == "1") : ?>
    				<div>
    					<?php echo $title; ?>
    					<?php echo $text; ?>
    				</div>
    			<?php elseif( $cols == "2") : ?>
    				<div class="blue">
    					<div class="col-sm-6">
    						<?php echo $title; ?>
    						<?php echo $text; ?>
    					</div>
    					<div class="col-sm-6">
    						<?php echo $texts; ?>
    					</div>
    				</div>
    			<?php endif;
    
    		endif; //get_row_layout
    
    	endwhile; //have_rows
    
    endif; //have_rows
    
    ?>
  • Glad that you managed to resolve it, with regards to wp_mail it should be semi-straight forward

    // Updates FYI last update timestamp when custom field is updated
    function my_acf_save_post( $post_id ) {
      // bail out early if we don't need to update the date
      if( is_admin() || $post_id == 'new' ) {
         return;
       }
       global $wpdb;
       $datetime = date("F j, Y g:i a");
       $query = "UPDATE $wpdb->posts
    	     SET
                  post_modified = '$datetime'
                 WHERE
                  ID = '$post_id'";
        $wpdb->query( $query );
    
        $to = '[email protected]';
        $subject = 'Update to ' . get_the_title($post_id);
        $message = "There has been an update to your post " . $get_the_title($post_id) . "/n You can click to see this here:" . get_permalink($post_id);
    
        wp_mail($to, $subject, $message);
        
    }
    // run after ACF saves the $_POST['acf'] data
    add_action('acf/save_post', 'my_acf_save_post', 20);

    This is untested mind, but it seems like it would work. Through using wp_mail() to send, it should follow standard site sending protocol (i.e. if you have an SMTP plugin or however your site sends by default).

  • Based on the code and the ACF field setup in your other post, this should work for you:

    <?php
    $title	= get_sub_field('title');
    $text	= get_sub_field('text');
    $texts	= get_sub_field('text_copy');
    $cols	= get_sub_field('columns');
    
    <?php
    // check if the flexible content field has rows of data
    if( have_rows('text_section') ):
    	while ( have_rows('text_section') ) : the_row();
    
    		if( get_row_layout() == 'blue_content_blocks' ) :
    
    			if( $cols == "1") : ?>
    				<div>
    					<?php echo $title; ?>
    					<?php echo $text; ?>
    				</div>
    			<?php elseif( $cols == "2") : ?>
    					<div class="col-sm-6">
    						<?php echo $title; ?>
    						<?php echo $texts; ?>
    					</div>
    			<?php endif;
    
    		endif; //get_row_layout
    
    	endwhile; //have_rows
    
    endif; //have_rows
    
    ?>

    Edit: variable name typo

  • There’s a range of methods you could use to get the same effect. You could have a checkbox to say “yes I want to use two columns” and then check / uncheck as necessary, a select box as you do, or even just filling out two textareas and checking if the second one has anything in it and if a second column is necessary.

    However you decide to do it, and however works best for you, it’s just important to keep in mind whether you’re looking at fields or sub_fields and using the correct function accordingly, otherwise it’ll stop working for no reason in particular.

    If any fields you reference are INSIDE the flexibile content, you need to use the_sub_field() or get_sub_field() to see any content.

    Hopefully that should resolve your problem and you’ll start to see some content come through

  • Don’t worry, you can always find your topics and replies if you look on your profile page 🙂

  • I just answered this in your other topic, don’t try and spam the same question otherwise it just dilutes the ability for people to actually help.

    https://support.advancedcustomfields.com/forums/topic/post-based-on-condition-of-field/

    Specifically in this instance however, your elseif will never fire because it is the same as your first if statement which has already run it’s code through and not had to do anything. ELSEIF statements only run if the first if statement has come back false.

  • Flexible Content works in much the same way as a repeater field, where you can check to see if there’s anything in it, and then reference all of the sub_fields within (note: sub_field).

    In your case, once you’ve performed your initial check for existence, grab the select sub_field and check if there should be one or two columns:

    
    <?php if(get_sub_field('columns_required') == "one_column") : ?>
    
        <div class="column wide">
            <?php the_sub_field('column_content'); ?>
        </div>
    
    <?php elseif( get_sub_field('columns_required') == "two_columns") : ?>
    
        <div class="column half_size">
            <?php the_sub_field('left_column'); ?>
        </div>
        <div class="column half_size">
            <?php the_sub_field('right_column'); ?>
        </div>
    
    <?php endif; ?>
    

    Hope that helps

  • Would this not be easier to have an extra text field with a custom date string in it that when the user submits the form you can use a combination of the pre_save_post filter along with the update_field() function to update this field, either to just include the default WordPress timestamp or to include your own?

    https://www.advancedcustomfields.com/resources/acf-pre_save_post/

    If there were other things going on on the page, or other acf form submissions that you didn’t want messing this up, you could specifically check to see if that field had been submitted by checking the post data to confirm that the name field had been changed:

    function my_pre_save_post( $post_id ) {
    
    	// in this example field_0987654321 is your name field and field_1234567890 is your date field 
    
    	if( $_POST['acf']['field_0987654321'] ) : 
    
    		// field_1234567890 needs to be the acf slug of the date field, not the field name
    	    update_field('field_1234567890', date('d/m/Y'), $post_id);
    
    	endif; 
    
    }
    
    add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 1 );

    Hope that helps? 🙂

  • Hi @bispawel,

    The important thing here is the repeater aspect, as opposed to the group itself. So within your post/page you’ll have a repeater that contains say 10 rows of data. It works a little bit like the WordPress loop. First, you check to see if there’s any data at all, then if there is data, you start a while loop to be able to access each repeater row individually.

    Because these are sub_fields you need to use get_sub_field() or the_sub_field() to reference that data. In practice, it should look a little bit like this:

    <?php
    
    // check if the repeater field has rows of data
    if( have_rows('kind_stuff') ):
    
    ?>
    
    <table>
    
    <?php
     	// loop through the rows of data
        while ( have_rows('kind_stuff') ) : the_row();
    
        	// attribute sub fields to variables
        	$stuff_name = get_sub_field('name');
        	$stuff_cost = get_sub_field('cost');
        	$stuff_photo = get_sub_field('photo');
        	$stuff_link = get_sub_field('link');
    
        	?>
    
        	<tr>
    
        		<td><img src="<?php echo $stuff_photo['url']; ?>" alt="<?php echo $stuff_photo['alt']; ?>" /></td>
    
        		<td><?php echo $stuff_name; ?></td>
    
        		<td><?php echo "$" . $stuff_cost; ?></td>
    
        		<td><a href="<?php echo $stuff_link; ?>">View product</a></td>
    
        	</tr>
    
        <?php endwhile; ?>
    
    </table>
    
    <?php
    
    else :
    
        // no rows found
    
    endif;
    
    ?>

    Depending on how you’ve set up each of those sub_fields will depend on specifically how you echo them out.

    edit: The Repeater documentation page may help you further: https://www.advancedcustomfields.com/resources/repeater/

  • I’ve just come up against this exact train of logic where I wanted to give the user a Yes/No option, but wanted to definitively confirm that they are actually clicking the button as opposed to skipping over it.

    I was initially concerned that allow_null would allow the field to submit as Null even if I also set it to required as it wasn’t clear from this thread, but just tried it out and found that this is not the case, which is brill.

    Radio loads in as empty, until clicked, at which point it will verify, the fact that it allows you to deselect it actually is somewhat arbitrary as you still can’t submit the changes at that point. Unless you changed the script to have the allow_null option turn off once a selection has been made?

    Either way, I just wanted to +1 this solution as a good one.

Viewing 19 posts - 26 through 44 (of 44 total)