Support

Account

Forum Replies Created

  • Edit* Sorry, I should also say I’ve tried 5.8.0-beta3 but to no avail
    Thanks

  • Managed to solve this – simply needed to change the priority on the add_action from 1 to 20

  • Thanks John,

    The route I went with (albeit clunky):
    1) Add extra fields to the checkout process (custom meta stored to order post id)
    2) Setup ACF fields and add them to the user (i’m using a role as a rule)
    3) Add a function that checks when we hit the Woo Order thank you page
    4) Use get_post_meta( $order_id, 'custom_field', $single = true); to get the field added at the checkout
    5) Use update_user_meta( $user_id, 'custom_field', $company_name ); to move the info to the user

    Whilst it’s not ideal it does achieve what I need. It also means I’ve a hard copy (so to speak) of the additional data submitted by the customer as it’s part of the order

  • Thanks Dave,

    Yep, that’s what I had. Am assuming it was the reason for the pop up

    At John, so instead of using the form fields,ref by key. Shall I still try form=>false as well?

  • Thanks @john huebner

    I did try that but in the end had to leave this option. Once the main WooCommerce form was triggered, it would then come up with a leave this page error, I assume it’s because I had the ACF form as well

    Many thanks for your reply though

  • Solved it!

    Replace:
    $i = add_row('field_595cec87bddf0', $row, $user_id);
    With:
    $i = add_row('field_595cec87bddf0', $row, 'user_'.$user_id);

    Note the user_ before the ID, otherwise it posts to the postmeta table not the usermeta table!

  • But if it works for a single field why not a repeater (excuse my ignorance)

    Even if I check the DB, not info is added, not even a new empty row

  • Thanks John Huebner

    I’ll take a look although it’s odd as the add_row code works inside the save_post function so not sure why it won’t in the ajax call

  • I’ve switched to:

    			$row = array(
    				'field_5947dbd28c36e'	=> $line[0],
    				'field_5947dbd78c36f'	=> $line[1],
    				'field_5947dbdc8c370'	=> $line[2],
    				'field_5947dbe48c371' => ''
    			);
    			
    			$i = add_row('field_5947dbbd8c36d', $row, $post_id);	

    And hey presto!

    Apologies

  • Apologies, I missed this part:
    $headers = array('From: ' . $user_info->first_name. ' '.$user_info->last_name . ' <'.$user_info->user_email.'>');
    Notice the header is an array!

  • Thanks @acf-support

    I managed to work it out!

    I added:

    
    	$mailResult = false;
    	#$mailResult = wp_mail( 'my@email.com', 'test if mail works', 'hurray' );
    	echo $mailResult;	
    

    I then worked out I had a typo!
    This line:
    $headers = 'From: ' . $user_info->first_name. ' '.$user_info->last_name . ' <' . $user_email .'>' . "\r\n";

    Should be:
    $headers = 'From: ' . $user_info->first_name. ' '.$user_info->last_name . ' <' . $user_info->user_email .'>' . "\r\n";

    Basically, the email didn’t have $user_info-> in front of it!

    Now working

    Cheers

  • Hi blueawesome

    You need to query the database, this article helped me: http://www.advancedcustomfields.com/resources/querying-the-database-for-repeater-sub-field-values/

    My code then had something like this:

    				<?php  
    				$last = count($rows);	
    				$i = 1; 				
    				foreach( $rows as $row ) {				
    					preg_match('_([0-9]+)_', $row->meta_key, $matches);	
    					$meta_key = 'team_' . $matches[0] . '_select_staff';
    					$user_id = get_post_meta( $row->post_id, $meta_key, true );									
    				?>

    Once I had the ID of the user, I could then do the following:
    <h5><?php $user_info = get_userdata($user_id); $first_name = $user_info->first_name; $last_name = $user_info->last_name; echo "$first_name $last_name"; ?><?php #echo ' - '.$user_id; ?></h5>
    I’ve no idea exactly what you’re trying to achieve but maybe the above will give you some pointers!

    jeremey’s code is useful but if you’re using a repeater then you need to go the query route I believe

  • Solved it with this:

                      <?php if(get_field('faqs')): while(has_sub_field('faqs')): 				  
                      $variable = get_sub_field('category'); 			  
                      if(get_sub_field('qa')): while(has_sub_field('qa')): ?>
    						  
    					<article class="envor-sorting-item <?php echo $variable; ?>">
    						<header><?php the_sub_field('question'); ?> <i class="fa fa-plus"></i></header>
    						<?php the_sub_field('answer'); ?>
    					</article>
    						  
                      <?php endwhile; endif; 
                      endwhile; endif; ?>

    Not sure what I was doing wrong before!! Hopefully it helps someone else

  • Thanks l.pirondini that really helped!

  • Thanks @elliot for the reply.

    I believe I’ve solved it. I’ve used the below to do what I need, not sure if there is a cleaner way though:

    <ul>
    <?php	
    $args = array( 
    	'post_type' => 'job_sectors',
    	'post_status' => 'publish',
    	'order'    => 'ASC',
    	'orderby'	=> 'name'
    );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    
    ?>			
    	<li><a href="<?php echo get_permalink($pageChild->ID);?>" title="<?php the_title(); ?>"><?php the_title(); ?><?php #the_ID(); ?></a>	
    	<?php
    	global $post;
    	$args = array(
    		'post_type' => 'jobs',
    		'meta_query' => array(
    			array(
    				'key' => 'job_sector',
    				'value' => get_the_ID(),
    				'compare' => 'LIKE'
    			)
    		)
    	);
    	
    	$myposts = get_posts( $args );
    	$total = 0;
    	foreach( $myposts as $post ) : 
    	$total = $total + $post; 
    	?>
    	
    	<?php endforeach; 
    	wp_reset_postdata(); 
    	echo "($total)"; 
    	?>
    	</li>
    
    <?php endwhile; ?>			
    </ul>

    Thanks

  • I use this if it helps@

    
    function custom_field_excerpt() {
    	global $post;
    	$text = get_field('overview');
    	if ( '' != $text ) {
    		$text = strip_shortcodes( $text );
    		$text = apply_filters('the_content', $text);
    		$text = str_replace(']]>', ']]>', $text);
    		$excerpt_length = 10; // 20 words
    		$excerpt_more = apply_filters('excerpt_more', ' ' . '...');
    		$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
    	}
    	return apply_filters('the_excerpt', $text);
    }
    function custom_field_excerpt_longer() {
    	global $post;
    	$text = get_field('overview');
    	if ( '' != $text ) {
    		$text = strip_shortcodes( $text );
    		$text = apply_filters('the_content', $text);
    		$text = str_replace(']]>', ']]>', $text);
    		$excerpt_length = 25; // 20 words
    		$excerpt_more = apply_filters('excerpt_more', ' ' . '...');
    		$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
    	}
    	return apply_filters('the_excerpt', $text);
    }

    Just ensure you change this bit to your field name:
    $text = get_field('overview');

    Then to call it I use:
    <?php echo custom_field_excerpt_longer(); ?>

    Cheers

  • Hi,

    Glad to hear you got it working. The above code certainly looks to be on the right lines and clearly returns your result so that must be a good thing.

    The double “” is basically:
    One closing ” as the opening one is on line 2 and the other is the closing ” from line 10

    Cheers

  • Sorry I forgot to say that bit. I use the File URL in the settings

    Hope that helps!?

  • You can then loop to get all the states and then loop within that to show the info you need – or something like that anyway :-/

  • I had similar.

    If you look at the below:

    $rows = $wpdb->get_results($wpdb->prepare( 
    "
    SELECT * 
    FROM wp_postmeta
    WHERE meta_key LIKE %s AND meta_value LIKE %s GROUP BY meta_value ASC",
    'dates_%_available_dates', ''.$year.''.$month.'%', 			
    ""		
    ));	

    You can see that dates_%_available_dates is the repeater field as it went:
    dates_0_available_dates
    dates_1_available_dates
    dates_2_available_dates
    etc

    Using the % allows you to be more dynamic, as you can search on all with the LIKE statement

    This is the link I used:

    It may help you with your code. I most certainly think rewriting your query to something like my example or the one in the link will help though

  • I use the repeater and add 2 parts:
    – File
    – Text Field

    Then I do this:

    
    			<?php if(get_field('downloads')): ?>
    			<ul class="downloads">
    			<?php while(has_sub_field('downloads')): ?>
    				<li><img src="<?php echo $image_path; ?>adobe_pdf_icon.png" width="31" height="33" /><a href="<?php the_sub_field('file'); ?>" target="_blank"><?php the_sub_field('file_name'); ?></a></li>
    			<?php endwhile; ?>
    			</ul>		
    			<?php endif; ?>
    

    Not sure if that helps you or not

  • So may be this example may help:

    $posts = get_posts(array(
    	'post_type'		=> 'event',
    	'posts_per_page'	=> -1,
    	'meta_query'		=> array(
    		'relation' => 'OR',
    		array(
    			'key' => 'location',
    			'value' => 'melbourne',
    			'compare' => '='
    		),
    		array(
    			'key' => 'location',
    			'value' => 'sydney',
    			'compare' => '='
    		)
    	)
    ));
     
    if($posts)
    {
    	foreach($posts as $post)
    	{
    		// ...
    	}
    }

    Or maybe something like this (untested):

    $rows = $wpdb->get_results($wpdb->prepare( 
    "
    SELECT * 
    FROM wp_postmeta
    WHERE meta_key LIKE %s GROUP BY meta_key ASC",
    'Locations', 			
    ""		
    ));	

    I’d be inclined to look at some examples. Maybe try running the SQL in PHPMyAdmin and then convert that into the code you need.

  • Hi,

    If I’ve understood then you can use the example code here.

    This will allow you to run a query based on your search criteria. You can also check out the Query posts with acf values on this page.

    As it’s the repeater, you may need to do some custom SQL work. I did something similar with the repeater and the date picker. You can see that here.

    Hopefully that will put you on track

  • Sorry to bring this one up again but sadly I still can’t get anywhere with it. I’ve altered my approach but still to no joy.

    Ok, for the time being I’ve created a message field with an image in it. The image has an ID of: myImgId

    I then created another message field with the following:
    <p>X:<span id="x"></span></p>
    And a Y message field:
    <p>Y:<span id="y"></span></p>

    I then have a repeater setup which has the following:
    – X (text field)
    – Y (text field)
    – Get Co-ords (message field)

    The Get Co-ords messgae field then contains:

    
    <script type="text/javascript">
    <!--
    function FindPosition(oElement)
    {
      if(typeof( oElement.offsetParent ) != "undefined")
      {
        for(var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent)
        {
          posX += oElement.offsetLeft;
          posY += oElement.offsetTop;
        }
          return [ posX, posY ];
        }
        else
        {
          return [ oElement.x, oElement.y ];
        }
    }
    function GetCoordinates(e)
    {
      var PosX = 0;
      var PosY = 0;
      var ImgPos;
      ImgPos = FindPosition(myImg);
      if (!e) var e = window.event;
      if (e.pageX || e.pageY)
      {
        PosX = e.pageX;
        PosY = e.pageY;
      }
      else if (e.clientX || e.clientY)
        {
          PosX = e.clientX + document.body.scrollLeft
            + document.documentElement.scrollLeft;
          PosY = e.clientY + document.body.scrollTop
            + document.documentElement.scrollTop;
        }
      PosX = PosX - ImgPos[0];
      PosY = PosY - ImgPos[1];
      document.getElementById("x").innerHTML = PosX;
      document.getElementById("y").innerHTML = PosY;
    }
    //-->
    </script>
    
    <script>
    function GetUrlValue(VarSearch){
        var SearchString = window.location.search.substring(1);
        var VariableArray = SearchString.split('&');
        for(var i = 0; i < VariableArray.length; i++){
            var KeyValuePair = VariableArray[i].split('=');
            if(KeyValuePair[0] == VarSearch){
                return KeyValuePair[1];
            }
        }
    }
    </script>
    
    <script type="text/javascript">
    <!--
    var myImg = document.getElementById("myImgId");
    myImg.onmousedown = GetCoordinates;
    //-->
    </script>
    
    <script type="text/javascript">
    function copy()
    {
    	var n1 = document.getElementById("x").innerHTML = PosX;
    	var n2 = document.getElementById("y").innerHTML = PosY;
    	
        field_key-field_526940f87b5b1.value = n1.value;
    	field_key-field_526941047b5b2.value = n2.value;
    }
    </script>
    
    <input type="button" value="copy" onClick="copy();" />
    

    The idea is that whenever you click a point on the image, the X and Y values are shown in the 2 respective message fields. On the repeater, you simply click the Copy button that is now shown and the values are copied into the respective input fields.

    Unfortunately, it simply doesn’t do this and I can’t see why.

    Any help is much appreciated
    Thanks

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

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.