Support

Account

Forum Replies Created

  • 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

  • This reply has been marked as private.
  • Hi

    I use if (++$i == 2) break; to stop the loop at 2 rows. EG.

    
    if( $rows ) {
     $i = 0;
     foreach( $rows as $row ) {
      if (++$i == 2) break;
     endif;
    }
    

    So you can change the 2 to a 6 to limit the number of values returned.

    Hope that helps!?

  • Sure.

    I’ve installed the timthumb code in its own directory within my theme.

    I then have a field within my repeater called image

    Finally, I have a line of PHP ($theme_path) which I call from my function file. This is simple the path to timthumbs files like so:
    $theme_path =’http://www.domain.co.uk/wp-content/themes/theme_folder/’;

    <img src="<?php echo $theme_path; ?>timthumb/timthumb.php?src=<?php the_sub_field('image'); ?>&w=618&h=298&q=100">

    That should get you what you need. Hope that helps

  • Daft question!

    How can I get the uploaded image into the JS script?

    Am massively struggling so any help is very much appreciated

    Thanks

  • Hi,

    Can you not use TimThumb? This is what I do and it works really well!

  • A-ha! Yes I have that lol

    Ok I will try again

  • Thanks again.

    I don’t have a html field though? Running the latest version and can’t see it. 🙁

  • Thanks Jonathan

    Actually, this isn’t as easy I first thought.

    Is it even possible to add an A tag within the repeater? I tried using a text field and the append option

    Something is telling me this is going to be a headache 🙁

  • Oh I see! Sorry, that makes sense now with regards to the a-tag (feeling embarrassed)

    I think this is coming together, my only concern is how to pass the X and Y value back from the pop up window to the repeater row.

    Otherwise I think this is all the pieces needed.

    Again, if anyone has any thoughts on this, please feel free to contribute. It would be good to get this available to all as I’m sure I can’t be the only one that needs this?!

  • Thanks Jonathan

    I’m sort of new to the ACF plugin. What does the -tag do?

    Would you not need to publish the post in order to view the image in order to have something to click to get the coordinates?

    Any code input is most welcome as I can’t work out where on earth to start. In my head it seems ok but trying to put it into code seems to be a right mare!!

  • OK,

    I’ve been giving this some thought and think I can work out the stages but need help with the code

    1) So you create a new post
    2) Upload an image to the custom field: Image
    3) Publish
    4) Ideally once published then a repeater field appears (is that easy to do?)
    5) The ACF repeater has:
    – Caption
    – URL
    – X coordinate
    – Y coordinate
    6) At the end of the repeater row you can click to open a pop up
    7) The pop up window contains this script but shows the image from the published post
    8) You click the image and to get an X and Y value
    9) These are then passed back to the repeater

    Am I over complicating this? Is there an easier solution?

    Any help is very much appreciated

  • Can you not simply use the first row of the repeater:

    <?php
     
    $rows = get_field('repeater_field_name' ); // get all the rows
    $first_row = $rows[0]; // get the first row
    $first_row_image = $first_row['sub_field_name' ]; // get the sub field value 
     
    // Note
    // $first_row_image = 123 (image ID)
     
    $image = wp_get_attachment_image_src( $first_row_image, 'full' );
    // url = $image[0];
    // width = $image[1];
    // height = $image[2];
    ?>
    <img src="<?php echo $image[0]; ?>" />

    Taken from here: Repeater Documentation

  • Ok, managed to solve it by swapping the SQl round a little, like so:

    			$rows = $wpdb->get_results($wpdb->prepare( 
    			"
    			SELECT * 
    			FROM wp_postmeta
    			WHERE meta_key LIKE %s AND meta_value LIKE %s ORDER BY meta_value ASC",
    			'dates_%_available_dates', ''.$year.''.$month.'%', 			
    			""		
    			));	
  • Ok, this now works as I need it. I wonder if the code can be tidied in anyway but it works. Here’s my code incase it helps anyone else.

    <?php
    #start from current month. Change 6 to however months ahead you want
    for ($x=0; $x<=6; $x++) {
    
    	$date = new DateTime("$x months");
    	$date->modify("-" . ($date->format('j')-1) . " days");
    	#echo $date->format('j, m Y');	
    	$month =  $date->format('m');
    	$year =  $date->format('Y');	
    	#echo 'Month= '.$month .' Year= '.$year.' <br>'; #debug
    
    	$rows = $wpdb->get_results($wpdb->prepare( 
    	"
    	SELECT * 
    	FROM upKeep_postmeta
    	WHERE meta_key LIKE %s
    		AND meta_value LIKE %s
    	",
    	'dates_%_available_dates', // meta_name: $ParentName_$RowNumber_$ChildName
    	#''.$year.''.$month.'%' // meta_value: 20131031 for example
    	''.$year.''.$month.'%' // meta_value: 20131031 for example
    	));
    			
    	// loop through the results
    	if( $rows ) {
    		echo '<h2>'.$date->format('F').' '.$date->format('Y').'</h2>';
    		echo '<ul>';
    		foreach( $rows as $row ) {
    			// for each result, find the 'repeater row number' and use it to load the sub field!
    			preg_match('_([0-9]+)_', $row->meta_key, $matches);
    			$meta_key = 'dates_' . $matches[0] . '_dates'; // $matches[0] contains the row number!
    			?>
    			<li><a href="<?php get_permalink( $row->post_id ); ?>"><?php echo get_the_title( $row->post_id ); ?></a></li>
    			<?php
    		}
    		echo '</ul>';
    	}
    }
    ?>
  • Thanks @elliot for the reply.

    I’ve started to look at the SQL method as I think this may work, however, I’ve come unstuck with the code. I know if I alter the SQL a little I can get it more or less to work for one month.

    So I’ve altered the code to loop for the next 6 months but it only returns 1 result

    Here’s my code:

    for ($x=1; $x<=6; $x++) {
    	#echo "Month is: $x <br>";
    
    	$date = new DateTime("$x months");
    	$date->modify("-" . ($date->format('j')-1) . " days");
    	#echo $date->format('j, m Y');
    	
    	$month =  $date->format('m');
    	$year =  $date->format('Y');
    	
    	echo 'Month= '.$month .' Year= '.$year.' <br>'; #debug
    
    	$rows = $wpdb->get_results($wpdb->prepare( 
    	"
    	SELECT * 
    	FROM upKeep_postmeta
    	WHERE meta_key LIKE %s
    		AND meta_value LIKE %s
    	",
    	'dates_%_available_dates', // meta_name: $ParentName_$RowNumber_$ChildName
    	''.$year.''.$month.'%' // meta_value: 20131031 for example
    	));
    			
    	// loop through the results
    	if( $rows ) {
    		echo '<ul>';
    		foreach( $rows as $row ) {
    			// for each result, find the 'repeater row number' and use it to load the sub field!
    			preg_match('_([0-9]+)_', $row->meta_key, $matches);
    			$meta_key = 'dates_' . $matches[0] . '_dates'; // $matches[0] contains the row number!
    			?>
    			<li><a href="<?php get_permalink( $row->post_id ); ?>"><?php echo get_the_title( $row->post_id ); ?></a></li>
    			<?php
    		}
    		echo '</ul>';
    	}
    
    }

    I think I’m being daft as I believe the above “should” work. Any help is much appreciated!

  • Hi,
    Could you not add a count to the loop and then start from greater than 1?

Viewing 24 posts - 26 through 49 (of 49 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.